?
Solved

Reference Cell Range with Counter

Posted on 2004-08-10
6
Medium Priority
?
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Introduction to Processes

719 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