Changing multiple cells not in a range

jplmac

New Member
Joined
Jul 21, 2011
Messages
1
Hi,

Is there a way to select multiple cells that would not make up a range or be resized e.g. 'B2' & 'D2'?

To explain, I have written an event handler macro, which will set the cell colour to grey for other cells in the row. The cells it will change will vary depending on what is filled in for column A (from a validation list). Because these cells are in non-adja
Code:
cent columns (e.g. B & D) I can't use range or resize, so I have to repeat With End With for each cell, meaning there is a lot of code.

I have only included part of the macro as an example.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Column
    Case 1
    
        ThisRow = Target.Row
    
        Select Case Target
            Case "Renamed"
                With Cells(ThisRow, 2).Interior
                    .Pattern = xlSolid
                    .TintAndShade = -0.249977111117893
                End With
                With Cells(ThisRow, 4).Interior
                    .Pattern = xlSolid
                    .TintAndShade = -0.249977111117893
                End With

            Case "Deleted"
                With Cells(ThisRow, 3).Interior
                    .Pattern = xlSolid
                    .TintAndShade = -0.249977111117893
                End With
                With Cells(ThisRow, 7).Interior
                    .Pattern = xlSolid
                    .TintAndShade = -0.249977111117893
                End With

        End Select
End Select
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I think that conditional formatting might be a worthwile alternative to look at.

If yoiu stick with VBA code, use a second procedure containing the code for 1 cell. Pass parameters to that cell and execute it (call the procedure) from the main event code.
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

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