How to merge 2 codes that do the same thing for 2 separate cells into 1 code?

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Please could someone help me?

I have this following 2 codes that works fine but I was wondering how it can be made into 1 code?

Code:
Cells(Rows.Count, "A").End(xlUp).Select

Selection.ClearComments


With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
End With


With Selection.Font
        .Name = "Gill Sans MT"
        .Size = 11
End With
    
Cells(Rows.Count, "B").End(xlUp).Select


Selection.ClearComments


With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
End With


With Selection.Font
        .Name = "Gill Sans MT"
        .Size = 11
End With

Any help would be much appreciated.

Thanks

Dan
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try:
Code:
Sub test()
    With Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 2)
        .ClearComments
        With .Interior
            .Pattern = xlNone
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        With .Font
            .Name = "Gill Sans MT"
            .Size = 11
        End With
    End With
End Sub
 
Upvote 0
If the last value in A and B could be on different rows, change the first line in Mumps' code to:

Code:
    With Union(Cells(Rows.Count, "A").End(xlUp), Cells(Rows.Count, "B").End(xlUp))
 
Last edited:
Upvote 0
Hi mumps,

Perfect once again, thank you.

Regards

Dan
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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