|
-
Feb 12th, 2006, 11:00 PM
#1
Thread Starter
New Member
Excel Macro Special Cell Selection
Your help here would be great .....
I am trying to use an excel macro to select 2 ranges on the same sheet:
- the first range is A1:G56
- the second range is I59 to the last active cell. This last active cell is always in column I and is always at least 10 rows greater than row 59.
The problem is that the macro that excel generates (below) always selects A1:I(x) where x is the last row number. eg if the last active cell in column I is 90, A1:I90 is selected. The ranges I do not need selected are A57:G90 and I1:I55.
Range("A1:G56,I59").Select
Range("I59").Activate
Range(Selection, ActiveCell.SpecialCells(xlCellTypeLastCell)).Select
Range(Selection, Selection.End(xlUp)).Select
Would really appreciate your help on this one.
Cheers
Marc
-
Feb 13th, 2006, 05:43 AM
#2
Re: Excel Macro Special Cell Selection
Hmm had a go. Weirdly doesn't like me make multiple range seklections using the range command :/
Guess it only works if you specify via address type (such as the recording you made already).
sorry couldn't help
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Feb 13th, 2006, 09:33 AM
#3
Re: Excel Macro Special Cell Selection
You cna use the Union Method to combine multiple ranges in excel. Here's some code that will union the ranges that you have described.
VB Code:
Sub MultiRangeSelect()
Dim rngTopSection As Range
Dim rngBottomStart As Range
Dim rngBottomSection As Range
Dim rngCombined As Range
Set rngTopSection = ThisWorkbook.Worksheets(1).Range("A1:G56")
Set rngBottomStart = ThisWorkbook.Worksheets(1).Range("I59")
Set rngBottomSection = Range(rngBottomStart, rngBottomStart.End(xlDown))
Set rngCombined = Application.Union(rngTopSection, rngBottomSection)
rngCombined.Select
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 13th, 2006, 10:19 AM
#4
Lively Member
Re: Excel Macro Special Cell Selection
Or
VB Code:
Sub SelectRange()
Dim r1 As Range, r2 As Range
Set r1 = ActiveSheet.Range("A1:G56")
Set r2 = ActiveSheet.Range("I59", Cells.SpecialCells(xlCellTypeLastCell))
ActiveSheet.Range(r1.Address & "," & r2.Address).Select
End Sub
BUT DKenny's solution is better (doesnt involve string concat operations)
Last edited by bilm_ks; Feb 13th, 2006 at 10:35 AM.
"bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)
-
Feb 13th, 2006, 05:54 PM
#5
Thread Starter
New Member
Re: Excel Macro Special Cell Selection
It works perfectly both ways - thank you both very much for your help - this has helped me put the finishing touches to a pricing system I have developed for work.
Cheers
Marc
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|