Solved

Reference Cell Range with Counter

Posted on 2004-08-10
6
307 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 125 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 125 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now