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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing multiple cells using variables

Status
Not open for further replies.

learning2fly

Programmer
Jan 10, 2001
12
GB
Hello,

This is probably totally obvious to an experienced VBA/Excel user. I am finding this problem increasingly frustrating though and would be grateful of some assistance.

I wish to select a group of cells in an Excel workbook using VBA code.


I use the command "Cells" to reference individual cells using variables but cannot seem to find an equivalent to select a group of cells.

For instance I want to select the range B3:B10 in a loop then C3:C10 etc.... and want to use variables to represent the loop iteration and the column length.

This is how I would like it to work:


For i=0 To NumColumns

Cells(2+i, 3: 2+i, 3+NumRows).Select

Selection.DoSomethingFantastic

Next i

But I cannot find the command that can use variables to select a group of cells.

Can anyone help?

Thanks

Gordon
 
Hi - try this:
For i = 0 To NumColumns
NumRows = 10
range(Cells(2, i),Cells(2 + NumRows, i)).Select

Selection.DoSomethingFantastic

Next i

Range(Cells(Row,Column),Cells(Row,Column))
is the syntax for multiple selection
HTH Rgds
~Geoff~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top