1

So here is my problem. I know we can define a range in VBA, say for example like Range("A1:A300"). Now say I have some integer x. I want the range from A1 to Ax. How can I write this in a code? Range("A1:Ax") clearly does not work

4
  • stackoverflow.com/q/6945949/11683 Commented Feb 3, 2015 at 8:50
  • Oh gee thanks a a lot for the down vote just say it's a duplicate and I would have deleted the question Commented Feb 3, 2015 at 8:53
  • GSerg, that "dupe", by the way, is way over-complicated for this specific need. It also won't handle AA thru whatever the current maximum column is :-) Commented Feb 3, 2015 at 8:55
  • @paxdiablo I did not vote for close as duplicate, otherwise there would be a close vote on the question. The question is not about Excel or ranges, it is about concatenating a string and a number. This question, while arguably not welcome on SO considering all the "please get a book on the language basics" comments these questions have generated, has been answered plenty of times, I simply dumped a link to the first one I found that shows the technique, with the added bonus of being in Excel context. Commented Feb 3, 2015 at 9:24

2 Answers 2

2

You can specify the anchor cell then extend:

range("A1").resize(300)
Sign up to request clarification or add additional context in comments.

Comments

1

That would be something like:

Range("A1:A" & CStr(x))

The CStr function will turn an integer into a string though I think you can actually just leave it off in later versions of Excel:

Range("A1:A" & x)

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.