ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What am I doing wrong with this VBA range? (https://www.excelbanter.com/excel-programming/418413-what-am-i-doing-wrong-vba-range.html)

jbarrington

What am I doing wrong with this VBA range?
 
This works:

Dim myRange As Range

Set myRange = Worksheets("Collection").Range("H2:H4")

But the change below doesn't work for some reason and presents an error:

Dim refColumn As String
Dim myRange As Range

refColumn = "H"

Set myRange = Worksheets("Collection").Range(refColumn & "2:" &
refColumn & "4")


What have I done wrong?

Thanks in advance.

Don Guillett

What am I doing wrong with this VBA range?
 
try

.range(cells(2,refcolumn),cells(4,refcolumn))

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"jbarrington" <"jbarrington -at- comcast period net" wrote in message
...
This works:

Dim myRange As Range

Set myRange = Worksheets("Collection").Range("H2:H4")

But the change below doesn't work for some reason and presents an error:

Dim refColumn As String
Dim myRange As Range

refColumn = "H"

Set myRange = Worksheets("Collection").Range(refColumn & "2:" &
refColumn & "4")

What have I done wrong?

Thanks in advance.



Rick Rothstein

What am I doing wrong with this VBA range?
 
That Set statement works fine for me (as it should) on my copy of XL2003.
Just out of curiosity, what error message are you getting? Are you sure the
Set statement is where your error is occurring at (that is, did you single
step through your code to see where the error pops up at)?

--
Rick (MVP - Excel)


"jbarrington" <"jbarrington -at- comcast period net" wrote in message
...
This works:

Dim myRange As Range

Set myRange = Worksheets("Collection").Range("H2:H4")

But the change below doesn't work for some reason and presents an error:

Dim refColumn As String
Dim myRange As Range

refColumn = "H"

Set myRange = Worksheets("Collection").Range(refColumn & "2:" &
refColumn & "4")


What have I done wrong?

Thanks in advance.




All times are GMT +1. The time now is 02:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com