How do I cycle through a list of Names and perform the same actions

Amateurhr

Active Member
Joined
Dec 26, 2011
Messages
343
I have a list of Names in comma separated form and I want each Name to go through a series of actions:

1) Application.Goto Reference:="Name1"
2) Range("Name1_variable").Copy
3) Take some other action

4) Then, repeat the sequence for Name2


How do I go about doing this?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Here is a bit of code I use to do it:

Code:
    intNames = ActiveWorkbook.Names.Count
    
    If intNames = 0 Then
        MsgBox "There are no names in this workbook."
        Exit Sub
    End If
    

    For i = 1 To intNames
    
      
        strName = ActiveWorkbook.Names(j).RefersTo
        
        If InStr(1, strName, "#REF") Or InStr(1, strName, "#N/A") Then
            ActiveWorkbook.Names(j).Delete
            intCount = intCount + 1
        Else
            j = j + 1
        End If
    
    Next i

Obviously the stuff in between would change to your copy and whatnot instead.
 
Upvote 0
Does this refer to all names in the Workbook? I have only a subset of Names I want to run through this process and they are in an excel cell in string format.
 
Upvote 0
Yes, it loops through all names. You can do a find on the name to see if it is contained in the string, if not, go to the next i.
 
Upvote 0

Forum statistics

Threads
1,216,108
Messages
6,128,872
Members
449,475
Latest member
Parik11

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