Solved

Select variable range of cells in Excel using VB

Posted on 2004-09-19
6
1,581 Views
Last Modified: 2012-06-22
I want to select a variable range of cells in an Excel worksheet. To cell is A1, bottom cell can be found by using SHIFT+CTRL+DOWN ARROW.

If I record this as a macro it records the absolute or actual cell identified when the macro is run, i.e. it can not be run as a general macro.

Is there a VB equivalent to SHIFT+CTRL+DOWN ARROW?

I'm using Office 2000
0
Comment
Question by:irh
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 12098875
try

vbkeyshift + vbkeycontrol + vbkeydown

or

vbkeyshift & vbkeycontrol & vbkeydown

mlmcc
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12100308
There is a special syntax to do this.

xlWB.ActiveSheet.Range("A1").Select  ' Begin select range
xlWB.ActiveSheet.Range(Selection, Selection.End(xlDown)).Select  ' Select till it spans
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12100312
Correct syntax

xlWB.ActiveSheet.Range("A1").Select
xlWB.ActiveSheet.Range(xlWB.ActiveSheet.Range("A1"), xlWB.ActiveSheet.Range("A1").End(-4121)).Select
0
 
LVL 13

Accepted Solution

by:
bochgoch earned 125 total points
ID: 12103257
Use this....

Set xlWB = xlApp.Workbooks.Open(useworkbook) ' useworkbook = existing workbook
Dim rng1 As Range
xlWB.Activate
Set rng1 = xlWB.Worksheets(1).UsedRange
0
 

Author Comment

by:irh
ID: 12592616
bochgoch's answer has worked on one of my sheets - but not on 2 others - not sure why at the moment!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

680 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