set range as multiple ranges VBA

Status
Not open for further replies.

twl2009

Board Regular
Joined
Jan 7, 2016
Messages
247
Im trying to use multiple ranges within the range 'Multirange', but have got something wrong. Was all working fine before with a single range.

Thanks

Code:
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993; background-color: #ffffff}span.s1 {color: #011993}span.s2 {color: #000000}</style>Private Sub Worksheet_Change(ByVal Target As Range)




Application.ScreenUpdating = False




Dim r1 As Range, r2 As Range, r3 As Range, r4 As Range
Dim MultiRange As Range
Dim isect As Range




If Target.Count > 1 Then Exit Sub




If Target.Address(False, False) = "B2" Then Call TitleCheck




If Target.Address(False, False) = "F2" Then Call DateCheck


Set r1 = Range("A11:G23")
Set r2 = Range("A26:G34")
Set r3 = Range("A38:G46")
Set r4 = Range("A50:G58")
Set MultiRange = Union(r1, r2, r3, r4)
Set isect = Intersect(Target, MultiRange)
If isect Is Nothing Then Exit Sub




If Application.WorksheetFunction.CountIf(MultiRange, Target) = 1 Then
    Set MyActiveCell = ActiveCell
    Sheets("Timesheet").Cells.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveSheet.Name = Target.Value & " Timesheet"
End If


Sheets("Labour Week").Activate
MyActiveCell.Select


Application.ScreenUpdating = True




[COLOR=#011993][FONT=Menlo]End[/FONT][/COLOR][FONT=Menlo] [/FONT][COLOR=#011993][FONT=Menlo]Sub[/FONT][/COLOR]/CODE]
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,815
Messages
6,121,715
Members
449,049
Latest member
THMarana

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