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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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