Reference Cell Range with Counter

I am populating an excel spreadsheet through automation in access. I am running into a problem when I try to reference multiple cells using a counter.

Ex:  I want to merge the last 2 rows in column G, and the Counter = 15

XlExcel.Range("G & Counter + 1:G" & Counter +2).Merge

I know that this works if you know what one of the cells would be such as
XlExcel.Range("G16:G" & Counter + 2).Merge
However, this will not work for my application.

I have tried variations of the above and have not gotten it to work yet.  Does anyone know what I am doing wrong?  Any help is appreciated.
Who is Participating?
EduskiConnect With a Mentor Commented:
XlExcel.Range("G & Counter + 1:G" & Counter +2).Merge

should be

XlExcel.Range("G" & Counter + 1 & ":G" & Counter +2).Merge
SNilssonConnect With a Mentor Commented:

Something like this maybe ?

iRange1 = Counter + 1
iRange2 = Counter + 2

sMyRange = "G" & iRange1 & ":G" & iRange2
slight mod

sMyRange = "G" & Cstr(iRange1) & ":G" & Cstr(iRange2)

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

must convert your ints to strings
slattbrAuthor Commented:
works, thanks

No not really, it works as in my first example, integers can be concatanated with strings without a problem, the other way around on the other hand is a problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.