Macro multiple range select

ApolloID

Well-known Member
Joined
Jun 8, 2010
Messages
769
Hi, i need to select two ranges but not like this:

Range("E4:P4,E5:P5").select

I need to split this in two...

Can this be done?

Thanks!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi

Can you elaborate on what you need? What do you mean by "need to split this in two"? Are you saying that you want to achieve the selection using two lines of VBA?

DK
 
Upvote 0
Code:
[COLOR="Blue"]Sub[/COLOR] SplitCells()
    
    [COLOR="Blue"]Dim[/COLOR] theAreas [COLOR="Blue"]As[/COLOR] Areas
    [COLOR="Blue"]Dim[/COLOR] rng1 [COLOR="Blue"]As[/COLOR] Range, rng2 [COLOR="Blue"]As[/COLOR] Range

    [COLOR="Blue"]Set[/COLOR] theAreas = Range("E4:P4,E5:P5").Areas
    
    [COLOR="Blue"]Set[/COLOR] rng1 = theAreas(1)
    [COLOR="Blue"]Set[/COLOR] rng2 = theAreas(2)
    
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Hi, i need to select two ranges for a chart, but the second range to offset with three rows, every time macro is looping.

Code:
Sub Loop2()
    Do
    Dim myrange As Range
Set myrange = Range("E4:P4,E5:P5")
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=myrange
    ActiveChart.ChartType = xlLineMarkers
    Loop Until IsEmpty(ActiveCell.Offset(2, 4))
End Sub

But i need this code to be something like this:

Code:
Sub Loop3()
    Do
    Dim myrange1 As Range
       Set myrange1 = Range("E4:P4")       
    Dim myrange2 As Range
       Set myrange2 = Range("E5:P5").offset(3, 0)
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:= myrange1,myrange2
    ActiveChart.ChartType = xlLineMarkers
    Loop Until IsEmpty(ActiveCell.Offset(2, 4))
End Sub

One problem is how to put together this part:

ActiveChart.SetSourceData Source:= myrange1,myrange2

...hopping the rest of the code will work (including the offset part)

Thanks alot!
 
Upvote 0
Or at least how to add offset to the second part of the range:
ActiveChart.SetSourceData Source:=Range("E4:K4,E5:K5")
to :

ActiveChart.SetSourceData Source:=Range("E4:K4,E5:K5.offset(3,0)")

Can this be done?
 
Upvote 0
Your loop doesn't advance anywhere.
Loop Until IsEmpty(ActiveCell.Offset(2, 4)) always uses same range .
 
Upvote 0
It worked in another situation.
maybe not here,...i did not test this macro because of the problem above.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top