Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stepping through a column in excel VBA

Status
Not open for further replies.

Jcan

Programmer
Jul 16, 2001
25
US
Hi, how can i step through an excel column using VBA without going through the thousands of empty cells in which there is no data?

Thanks a latte

Jcan
 
by 'the thousands of empty cells in which there is no data' I am assuming you mean the cells at the bottom of the worksheet after your data.

If I am wrong, please ignore the rest.

You can limit your looping by using the 'UsedRange' property of the WorkSheet object.

E.g.,

Dim oRange As Range
Dim oSheet As Worksheet
Dim oColumn As Range
Dim oCell As Range
Dim i As Long

Set oSheet = ActiveWorkbook.ActiveSheet
Set oRange = oSheet.UsedRange
Set oSheet = Nothing

Set oColumn = oRange.Columns(3)'replace 3 with whatever

Set oRange = Nothing

For i = 1 To oColumn.Rows.Count
Set oCell = oColumn.Rows(i)
Debug.Print i, oCell.Text
Set oCell = Nothing
Next i

Set oColumn = Nothing

' excuse the 'round-about' method but I wanted to use Intellisense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top