English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i want to select Cells(x, "A") to Cells(x, "Z") using macro VBA.

2007-11-08 08:18:21 · 2 answers · asked by Anonymous in Computers & Internet Software

2 answers

Try this code:

Sub test()

Application.ActiveSheet.Range( Cells(10, 1), Cells(10, 5)).Select

End Sub

Visit my site !!!!
http://www1.webng.com/nbittencourt/index_e.htm

2007-11-08 12:16:37 · answer #1 · answered by nbittencourt 3 · 0 0

The first answerer is a little off. If you already know you are using the active sheet there is no reason to write the extra code to specify that. As I'm guessiong you already know Cells works like this:

Cells(Row, Column)

However you cannot use the letter of the column in Cells. To select cells A1 To Z28 you'd have to do one of the following:

Range("A1:Z28").Select

or

Range(Cells(1, 1), Cells(28, 26)).Select

Notice that I don't specify the Application or ActiveWorkbook or ActiveSheet. All of that is already implied when I start out with Range. So if you add all of the extra stuff that the first person did, you are just wasting memory space on the computer and wasting time writing the macro by having to do extra typing.

When you use Cells you have to specify the column number. Z is the 26th column so you'd have to use 26 instead of "Z".

If you are using x as a variable to cycle through the rows, make sure that you set it as a Long variable. So you'd want to enter:

Dim x As Long

Don't set the variable as an Integer for your rows. The Integer data type only goes up to 30,000 some. So it won't reach the last row in the worksheet if you need it to.

2007-11-09 06:49:53 · answer #2 · answered by devilishblueyes 7 · 0 0

fedest.com, questions and answers