how do i set an entire row or column to a range?


S

strataguru

hi,

how do i set an entire row or an entire column to a range?

thanks
 
Ad

Advertisements

B

Brad Vontur

You're gonna laugh:

set rng = Range("A1").EntireColumn

or

set rng = Range("A1").EntireRow

And they call it BASIC??

-Brad
 
R

Rick

Hi,

Is this what you are looking for?

Sub SetRanges()
Dim rng As Range

MsgBox "First the column... "
Set rng = Range("G:G")
rng.Select

MsgBox "and now the row... "
Set rng = Range("20:20")
rng.Select

MsgBox "and now back to home. "
Range("A1").Select

End Sub

I hope that helps.

Rick
 
S

strataguru

what if i only know of the column number (or row number) based on an int
value in a field called colNum?

for example - if in my code the logic determines that the range needs
to be 3 (meaning colNum = 3)

i'm getting an error "Method 'Range' of object '_Global' failed." with
the statement:

Set rngWs = Range(colNum).EntireColumn

Thanks!
 
T

Tom Ogilvy

Set rngWs = Columns(colNum).Cells

set rngWs = Rows(rowNum).Cells

if you don't use the cells, you will get a range object of size 1 (the
entire column or entire row). Same with the other suggested approached

Set rngWs = cells(1,colNum).EntireColumn
? rngWs.count
1

so if you were going to loop through the cells of the column, you wouldn't.
If you were going to insert a column or set the column width, then you could
proceed without using the cells qualifier.
 
D

Don Guillett

try
Sub setcol()
Set wsrng = Columns(1)
wsrng.Select
End Sub
 
Ad

Advertisements

O

Otto Moehrbach

Very good to know that Tom. I would have lost some more hair if I tried to
loop through the cells. Otto
Tom Ogilvy said:
Set rngWs = Columns(colNum).Cells

set rngWs = Rows(rowNum).Cells

if you don't use the cells, you will get a range object of size 1 (the
entire column or entire row). Same with the other suggested approached

Set rngWs = cells(1,colNum).EntireColumn
? rngWs.count
1

so if you were going to loop through the cells of the column, you wouldn't.
If you were going to insert a column or set the column width, then you could
proceed without using the cells qualifier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top