Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reference Cell Range with Counter

Posted on 2004-08-10
6
Medium Priority
?
338 Views
Last Modified: 2010-04-17
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.
0
Comment
Question by:slattbr
6 Comments
 
LVL 8

Assisted Solution

by:SNilsson
SNilsson earned 500 total points
ID: 11764094

Something like this maybe ?

iRange1 = Counter + 1
iRange2 = Counter + 2

sMyRange = "G" & iRange1 & ":G" & iRange2
 
XlExcel.Range(sMyRange).Merge
0
 
LVL 3

Accepted Solution

by:
Eduski earned 500 total points
ID: 11764140
XlExcel.Range("G & Counter + 1:G" & Counter +2).Merge

should be

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

Expert Comment

by:bramsquad
ID: 11764146
slight mod

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

~b
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:bramsquad
ID: 11764155
must convert your ints to strings
0
 

Author Comment

by:slattbr
ID: 11764224
works, thanks
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 11764245

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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Screencast - Getting to Know the Pipeline

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question