Solved

Select variable range of cells in Excel using VB

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now