Solved

Select variable range of cells in Excel using VB

Posted on 2004-09-19
6
1,578 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

776 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