Referencing columns in formula

B

Bigfoot17

I started out selecting a range like this:
Range("B13:G13").Select

Then I realized that I wanted to use a variable for the row instead of 13
and changed it to this:
Range("B" & strRow & ":G" & strRow).Select

Now I want to be able to use a variable for the column. I'd like to select
"B" through the 5th column over ("G") or if my starting column is "I" then
select through the 5th column over ("N"). Below is wrong, but what would be
correct?
Range(strCol & strRow & ":" & (strCol + 5) & strRow).Select

Thanks!
 
R

Rick Rothstein

Use the Cells property in combination with Resize to do what you want...

Cells(strRow, strCol).Resize(, 5).Select

Although I'm willing to bet you don't actually need to select the range in
order to do whatever it is you want to do to the range (you didn't tell us).
By the way, strCol can either be the column number or column letter... the
Cells property will tolerate both forms of specifying the column.
 
R

ryguy7272

This should give you a few ideas:

Sub SelRange()
Dim MyRng As Range
Set r = Application.InputBox(prompt:="select range with mouse", Type:=8)
r.Select
If TypeOf Selection Is Range Then
Set MyRng = Selection
End If
End Sub

HTH,
Ryan---
 

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