Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
QB QB is offline
external usenet poster
 
Posts: 57
Default Col number not letter

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,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Col number not letter

Columns(1).Resize(,lstCol).Select

--
__________________________________
HTH

Bob

"QB" wrote in message
...
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,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Col number not letter

you almost had it ...

With Range("7:" & lstCol
'do something
Next


The example is deliberate ...you don't need to select a range to use it.
to color the above rave, just add the method

.Interior.Color=vbRed
.Font.Bold = True







"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,

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Col number not letter

In the VBA help file there are several sections that provide detailed
descriptions of how to use various references of cells, rows and columns.
To access these files, press Alt +F11, then open the help facility and ente
"How to Reference Cells and Ranges" in the help search box and press enter.
When the topic menu appears click on that topic. It will display about ten
additional topics that give various eplanations and examples of how to use
the A1 notations and the index notations for referencing cells, rows and
columns.



"QB" wrote in message
...
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,



  #5   Report Post  
Posted to microsoft.public.excel.programming
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,

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a number to a letter of the alphabet to get a letter [email protected] Excel Worksheet Functions 5 May 21st 07 04:25 PM
How do i set up a list that sorts as Number/letter/number in orde xorex Excel Discussion (Misc queries) 3 September 8th 06 12:59 AM
change headers from letter to number/number to letter lazybee Excel Worksheet Functions 1 July 29th 05 11:08 PM
column header changed from letter to number, how return to letter Ron Excel Discussion (Misc queries) 2 May 9th 05 08:34 PM
Auto number w/ different letter-number combos in same column Colleen B Excel Worksheet Functions 2 February 23rd 05 02:41 PM


All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"