View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Determine the last column of data

Bryan,

You asked "Why is Cells done different?"

I wondered the same thing when I got started with VBA.
There are some logical inconsistencies in VBA that may make sense behind the covers.
May own cynical view is that many are done on purpose for questionable reasons.

Enough of that, Range("B5") is a slightly more efficient way to refer to a cell than Cells(5,2).
However, trying to increment the characters in a range callout is exceedingly slow.
You would have to use something like Range("B" & N) and that is very inefficient.
It is much faster to use the cells method....Cells(N, 2).
You will not see the difference when doing just a few cells, but with programs
running large loops you could be talking several minutes versus a few seconds.

Regards,
Jim Cone
San Francisco, CA

"Bryan Kelly" wrote in message m...

How do I increment characters?


How to increment...
Take a look at loops (For/Next) in help for more information.
Note that "Cells" uses row as the first argument and column as the second.

Dim lngNum As Long
For lngNum = 1 To Columns.Count
If Len(Cells(1, lngNum)) = 0 Then
MsgBox "Column " & lngNum & " in row 1 is effectively empty"
Exit For
End If
Next 'lngNum


The reason I asked the question the way I did was that in my very limited
experience, a cell is identified in
the manner LN or letter followed by number, which is column first then row.
I just looked at Range and
it is described in terms of A1 through A5. Why is Cells done different? Or
is Range the different one?

So this seems to side step the question of incrementing letters to build a
Range identifier. Can I (Should I) completely avoid that problem by using
the Cells objects/methods?

Bryan
<SNIP