Combining Two Ranges together.

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey excel Gurus,

How do you combine 2 different ranges together with a With statement.

Code:
        With Range("A2:A1000" & "U1:FO1")

is the above correct?
thank you.
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
Function InRange(Range1 As Range, Range2 As Range) As Boolean
' returns True if Range1 is within Range2
Dim InterSectRange As Range
    Set InterSectRange = Application.Intersect(Range1, Range2)
    InRange = Not InterSectRange Is Nothing
    Set InterSectRange = Nothing
End Function




Sub ColourChange2()
  If InRange(ActiveCell, Range("U2:FO1000")) Then
    With Range("A2:A1000")
        .Font.ColorIndex = 1
    End With
    With Range("U1:FO1")
        .Font.ColorIndex = 1
    End With
            Range("A" & ActiveCell.Row).Font.ColorIndex = 4
            With Cells(1, Selection.Column)
                .Font.ColorIndex = 4
            End With
  Else
    With Range("A2:A1000")
        .Font.ColorIndex = 1
    End With
    With Range("U1:FO1")
        .Font.ColorIndex = 1
    End With
  End If
End Sub

I tried to do that with the above code by was not successful..
 
Upvote 0
Code:
Sub a()
Dim r1 As Range, r2 As Range, r3 As Range
Set r1 = ActiveSheet.Range("a1:a10")
Set r2 = ActiveSheet.Range("b1:b10")
Set r3 = Union(r1, r2)
r3.Select
End Sub
:beerchug:
 
Upvote 0
Code:
   With Range("A2:A1000,U1:FO1")
      .Font.ColorIndex = 1
   End With
works for me.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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