ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Converting col number to alpha letter to use in a range... (https://www.excelbanter.com/excel-programming/380559-converting-col-number-alpha-letter-use-range.html)

Lakehills

Converting col number to alpha letter to use in a range...
 
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


Dave Peterson

Converting col number to alpha letter to use in a range...
 
Range("a1",cells(1,lastcol)).select
is one way.
range("a1:a" & lastcol).select
is another

Lakehills wrote:

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


--

Dave Peterson

Lakehills

Converting col number to alpha letter to use in a range...
 
Worked like a charm Dave. Thanks much for the help!

CJM



All times are GMT +1. The time now is 08:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com