How to define multiple non-contiguous ranges?

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
I want to define lots of ranges that are comprised of every 5th column (starting at Col D through to Col AV) from Row 9 to Row 200 for each one.

Is there an easy way to do this?

I want this so I can set up a "tick" column along the lines of:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

'This macro inserts a "tick" in a cell that is double clicked
'The tick is the letter "a" in the Martlett format group
'Range where this takes place is union of ranges "name ranges here" etc

Dim tickRange As Range

Set tickRange = Union([Range1], [Range2], [Range2])

    If Not Intersect(Target, tickRange) Is Nothing Then

            Cancel = True 'Prevent going into Edit Mode

            Target.Font.Name = "Marlett"

                If Target = vbNullString Then

                    Target = "a"

                Else

                    Target = vbNullString

                End If

    End If

End Sub

This all looks very inelegant - is there a neater way??

thanks in advance
 

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).
The regularity of your discontinuous range allows for a test like this.
Code:
With Target
    If (.Column Mod 5) = 4 And (9 <= .Row) And (.Row <= 200) Then
        Rem your code
    End If
End With

But for a more random collection of Columns, You could use something like.

Code:
Set TickRange = Range("D1, I1, N1, M1, ...")
Set TickRange = Application.Intersect(Range("9:200"), TickRange.EntireColumn)

If Application.Intersect(Target, TickRange) Is Nothing Then
    Rem your code
End If

If you have an even uglier range to act on, you could take a completely different approach. Tag each cell that you want it to act on.
Code:
If Target.Validation.InputTitle = "action cell" Then

The bad thing about this approach is that each of the cells have to be tagged.
(Serves the developer right for using weird, irregular, non-column, non-row ranges. :) )
The nice thing about using .Validation.InputTitle for a tag is that it won't error, even if Validation hasn't been set for that cell.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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