Hightlight_named_range except name Print_Area

vietnguyen1211a

New Member
Joined
Feb 23, 2024
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
i edit that , but its not run correctly , someone can help me? please

Sub hightlight_named_range()
Dim Print_Area As Name
Dim RangeName As Name
Dim SelectedRange As Range

On Error Resume Next
For Each RangeName In ActiveWorkbook.Names

If RangeName <> Print_Area Then
Set SelectedRange = RangeName.RefersToRange
SelectedRange.Interior.ColorIndex = 20
End If

Next RangeName
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Please try the following on a copy of your workbook. Run the macro with the correct sheet active.

VBA Code:
Option Explicit
Sub RangeColor()
    Dim nm, s As String
    Dim wb As Workbook
    Set wb = ActiveWorkbook
    For Each nm In wb.Names
        If InStr(1, nm.Name, "Print_Area") = False Then
            s = nm.Name
            ActiveSheet.Range(s).Interior.ColorIndex = 20
        End If
    Next nm
End Sub
 
Upvote 0
In case you have additional named ranges in the workbook (other than in the active sheet), we better include an error handler:

VBA Code:
Option Explicit
Sub RangeColor()
    Dim nm, s As String
    Dim wb As Workbook
    Set wb = ActiveWorkbook
    For Each nm In wb.Names
        If InStr(1, nm.Name, "Print_Area") = False Then
            s = nm.Name
            On Error Resume Next
            ActiveSheet.Range(s).Interior.ColorIndex = 20
            On Error GoTo 0
        End If
    Next nm
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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