Solved

Select variable range of cells in Excel using VB

Posted on 2004-09-19
6
1,584 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
[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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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