List of names inserted into VBA Code

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I have a named range for Entries which is a list of names for my event
Excel Formula:
=OFFSET(Entries!$A$10,0,0,COUNTA(Entries!$A$10:$A$209),1)
I want to start with the first name, enter the value in Range ("Receipt!C48")
Then run my code
then put the next name on the list into Receipt!C48
Then run my code again
Continue this until the last name is entered.
I am running the macro while on the Receipt Worksheet and the list of names are in the Entries worksheet. My code needs to run on the Receipt Worksheet.

I have worked with looping macros and can do this but my way is exceedingly slow and clumsy.
Can anyone please help me with a code which will run quickly and efficiently to do this.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
The loop construction is quick and easy. One way you could do do this:

In Excel, Receipt!C48:= Index(Entries,N) where N is an Excel range name.

VBA Code:
Dim i As Long

Application.ScreenUpdating = False

For i = 1 To Range("Entries").Rows.Count
    Range("N").Value = i
    'run your code here
Next i

Application.ScreenUpdating = True

I suspect it's your code here, rather than your looping, which is slow.
 
Upvote 0
Solution
The loop construction is quick and easy. One way you could do do this:

In Excel, Receipt!C48:= Index(Entries,N) where N is an Excel range name.

VBA Code:
Dim i As Long

Application.ScreenUpdating = False

For i = 1 To Range("Entries").Rows.Count
    Range("N").Value = i
    'run your code here
Next i

Application.ScreenUpdating = True

I suspect it's your code here, rather than your looping, which is slow.
It was the clumsy way I was creating my code to get the looping. This is so simple and works like a charm. Thank you so much
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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