Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to refer dinamically to columns in excel 1

Status
Not open for further replies.

Davide77

Technical User
Mar 6, 2003
166
CH
here is the problem:

I'm formatting an excel sheet depending on the quantity of records that are going to be (automatically) inserted. The quantity can change. So I have to count the number of records and use this number in order to select the right cells to be formatted. There is no problem for the rows because they are named with numbers, so I can refer to them with variables:

.Rows("4:" & RecordQuantity).VerticalAlignment = 2

will align the rows number 4 to row number "recordquantity" that is a variable with the number of record.

I would like to do the same with columns but how can I refer to them if their names are letters "A", "B"...

Any ideas?
 
Take a look at the .Cells(numLig,numRow).Columns syntax.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
You can use
columns("A")
OR
columns(1)

You can also use

Cells(row_num,col_num)
cells(1,1) A1
OR
Cells(row_num,col_Letter)
cells(1,"A") A1

Rgds, Geoff
[blue]Experience is something you don't get until just after you need it[/blue]
We want to help [red]you[/red] Help us by reading this FAQ 1st faq222-2244
 
thanks to both,
i've tried your suggestions but i'm not sure if they are th right ones.
What I need is to refer to a part of collumn, something like from cell(1,1) to cell(1,8), without using the letter name of the collumn.
 
Use

Range(Cells(1,1),cells(1,8)).select

To select A1:H1

OR

Range(Cells(1,1),cells(8,1)).select

To select A1:A8


Rgds, Geoff
[blue]Experience is something you don't get until just after you need it[/blue]
We want to help [red]you[/red] Help us by reading this FAQ 1st faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top