Converting col number to alpha letter to use in a range...

L

Lakehills

Hello all,

This is probably a stupid question, but here goes...

My task is to select all the cells in row one (the header row) that
have data in them so I can apply formatting to them.

With the code below, I determine the last used colum, but "LastColumn"
is an integer. Assuming the first column is "A" and the row is always
1, how can I format the range statement? (or is there another way to
do this?)

' Determine last used column...

If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Columns.
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
MsgBox LastColumn
End If

' Select range ...
Range("A1:?1").Select

Can someone point me in the right direction?

Thanks,
CJM
 
D

Dave Peterson

Range("a1",cells(1,lastcol)).select
is one way.
range("a1:a" & lastcol).select
is another
Hello all,

This is probably a stupid question, but here goes...

My task is to select all the cells in row one (the header row) that
have data in them so I can apply formatting to them.

With the code below, I determine the last used colum, but "LastColumn"
is an integer. Assuming the first column is "A" and the row is always
1, how can I format the range statement? (or is there another way to
do this?)

' Determine last used column...

If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Columns.
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
MsgBox LastColumn
End If

' Select range ...
Range("A1:?1").Select

Can someone point me in the right direction?

Thanks,
CJM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top