List of names inserted into VBA Code

brianfosterblack

Board Regular
Joined
Nov 1, 2011
Messages
246
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,245
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

brianfosterblack

Board Regular
Joined
Nov 1, 2011
Messages
246
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
 

Forum statistics

Threads
1,141,125
Messages
5,704,440
Members
421,349
Latest member
Santhosh3188

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
Top