Looping through named ranges

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have a number of named ranged on a worksheet, some are just once cell and others consist of a number of cells.

I have been trying to use the following code to loop through each named range, but I cannot seem to get it to work.
Code:
Dim rngCheck As Range
Dim wsSheet As Worksheet

'On Error GoTo EH

If ActiveWorkbook.Name = "North Bank Control Sheet Template.xls" Then
    Set wsSheet = Sheets("Control Sheet")
    For Each rngCheck In wsSheet
        If rngCheck = "" Then
            Else
            MsgBox ("Data present")
            'do something here as there is data in worksheet
        End If
    Next
    Else
End If

'Exit Sub

'EH:

'MsgBox (Err.Description)


End Sub
Any comments would be appreciated.


Thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I realise that this has nothing to do with your actual code but hopefully it will give you some ideas about 'Union'

Code:
Sub Union ()
Dim CMS, Section1ContractName, MyRanges, Section1Applicant As Range

Set Section1ContractName = Range("e8")
Set CMS = Range("I3")
Set Section1Applicant = Range("E9")
 
Set MyRanges = Union(Section1ContractName, CMS, Section1Applicant)
 
  
For Each Ranges In MyRanges
If MyRanges = "" Then MsgBox "This Range is Empty""
Next Ranges
 
 
End Sub

DP
 
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,148
Members
449,066
Latest member
Andyg666

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