Set properties for multiple ranges

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Just a quick question I think, I want to set the properties of certain cells in more than 1 range and was wondering if this is possible. To explain better here is a portion of my code

Code:
With ws2.Range("A18")
.Value = "Name"
.BorderAround ColorIndex:=0, Weight:=xlThin
.Interior.Color = RGB(204, 192, 218)
.Font.Bold = True
.Locked = False
End With


Now I also want to give A29, A40, A51, etc the same properties and was wondering if it were possible to include them in the same with statement, rathing than having to copy and paste the whole thing and just change the cell reference?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try:
Code:
With ws2.Range("A18, A29, A40, A51")
    .Value = "Name"
    .BorderAround ColorIndex:=0, Weight:=xlThin
    .Interior.Color = RGB(204, 192, 218)
    .Font.Bold = True
    .Locked = False
End With
 
Upvote 0
Thought it would just be something simple,

Thank you, that saves me a lot of wasted typing time
 
Upvote 0
Okay, so I've now made things a little more complicated. Is it possible to do the same thing, but do so using an offset?

So instead of Range("B18, B29, B40, B51") I could say

Range("B18, B18.Offset(NoM, 0), B18.Offset(NoM * 2, 0), B18.Offset(NoM * 3, 0)

Where NoM is a variable

NoM = Sheets("MainMenu").cboName.ListCount +1
 
Upvote 0
I'd be tempted to use a loop thusly:

Code:
For i = 1 To 3
    With ws2.Range("B18").Offset(nom * i, 0)
        .Value = "Name"
        .BorderAround ColorIndex:=0, Weight:=xlThin
        .Interior.Color = RGB(204, 192, 218)
        .Font.Bold = True
        .Locked = False
    End With
Next i
 
Upvote 0
Thank you, I think I should be able to use that method to fit exactly what I need.
 
Upvote 0

Forum statistics

Threads
1,224,579
Messages
6,179,656
Members
452,934
Latest member
mm1t1

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