View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Col number not letter

You need to convert your column numbers into a string with letters. For
example, we want columns G thru S:

Sub columnAte()
n1 = 7
n2 = 19
Set r = Range(Cells(1, n1), Cells(1, n2))
s = r.Address(RowAbsolute:=False, ColumnAbsolute:=False)
s = Replace(s, "1", "")
MsgBox (s)
Columns(s).Select
End Sub

--
Gary''s Student - gsnu200905


"QB" wrote:

I recorded a macro which gave

Columns("A:M").Select

However, I need my code to be a little adaptive so I initially determine the
last column in the row

Range("A1").Select
Selection.End(xlToRight).Select
lstColCell = ActiveCell.Address
lstCol = ActiveCell.Column

As such, lstCol returns a number, not a letter like the nicely generate
macro code requires. How can I use the lstCol in the macro code?

I tried
Columns("1:" & lstCol).Select

But this didn't work.

Thank you for the help

Qb,