1

I am trying to pass a varible in Range but I am not able to, so the whole question is, I have two varibales a and b where values can be changed. now I want to select this range, but I am not able to select it as a range in VBA.

a  = ActiveCell.Address  ' suppose it returns me A3 

b = ActiveCell.Offset(20, 0).Address  ' suppose it returns me A23

Set d = range("a:b")  ' here i want to select A3:A23, but I am not able to 

d.select

Please help

0

3 Answers 3

1

You suppressed a and b in the range statement with quotes. They're being read as literals. Unquote them.

a  = ActiveCell.Address  ' suppose it returns me A3  
b = ActiveCell.Offset(20, 0).Address  ' suppose it returns me A23
Set d = range(a & ":" & b)  ' here i want to select A3:A23, but I am not able to 

d.select
Sign up to request clarification or add additional context in comments.

1 Comment

Pretty awesome, sorry for my dumbness
1

Small mistakes. Try this.

a = ActiveCell.Address  'Get A3 

b = ActiveCell.Offset(20, 0).Address  'Get A23

Range(a, b).Select  'Select A3:A23

Comments

0

Set d = Range(a, b) should do it. You know that Range(ActiveCell, ActiveCell.Offset(20, 0)).Select does the same? Also, you shouldn't need to select a range, if you want to copy for example, you would just use Range(ActiveCell, ActiveCell.Offset(20, 0)).Copy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.