Macro Help for a Complete Novice!

The Gent

Board Regular
Joined
Jul 23, 2019
Messages
50
Hi guys,

Macro basic level user here.

I have created a macro but I need some help to get it a bit slicker as I have bolted it together like lego. I would also like the macro to repeat by looking at a list as opposed to me running it 200+ times.

Current code:

Sub NEXTINLIST()
Dim v As Variant
Windows("Ecc vs S4.xlsx").Activate
With Sheets("Reconciliation").Range("B4")
If .Value = "" Then
.Value = Sheets("Locations").Range("A2").Value
Else
v = Application.Match(.Value, Sheets("Locations").Range("A2:A263"), 0)
If IsNumeric(v) Then
.Value = Sheets("Locations").Range("A2:A263").Cells(v + 1, 1).Value
Else
.Value = ""
End If
End If
'
Windows("Ecc vs S4.xlsx").Activate
Range("G1:G4").Select
Selection.Copy
Windows("Reconciliation 2 Progress Tracker.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Selection.Offset(1, 0).Select
'
End With
End Sub


Further info:
  • 'Locations' sheet has a list of 262 company's that I want the macro to look up to from C2:C63. I want the macro to repeat until it gets to the bottom of this list.
  • After B4 in 'Reconciliation' has been selected the sheet needs to refresh to pull figures from a database. This is why I can't loop the macro at the moment, as the macro continues whilst the database is still refreshing.
 

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.
Hi there. Can't do much with this at the moment (too busy with work work), but if you need to wait until refreshes are done, put this line in and it will stop at that point until all refreshes are complete:

Code:
application.CalculateUntilAsyncQueriesDone
 
Last edited:
Upvote 0
Hi there. Can't do much with this at the moment (too busy with work work), but if you need to wait until refreshes are done, put this line in and it will stop at that point until all refreshes are complete:

Code:
application.CalculateUntilAsyncQueriesDone

Great thanks.

Any suggestions on how to get this to loop until reaching the bottom of a list?

Regards.
 
Upvote 0
I will try to look at it tonight - it won't be difficult. Can you spell out in a bit more detail which bits need to loop, and where the results will go to?
 
Last edited:
Upvote 0
I will try to look at it tonight - it won't be difficult. Can you spell out in a bit more detail which bits need to loop, and where the results will go to?

Sure...

Current code:

Sub NEXTINLIST()
Dim v As Variant
Windows("Ecc vs S4.xlsx").Activate
With Sheets("Reconciliation").Range("B4")
The above location currently looks to a data validation list, this is the list that I want the macro to run through until it reaches the bottom of the list.

If .Value = "" Then

.Value = Sheets("Locations").Range("A2").Value
List is in the above location an spans from A2:A263, i.e. the macro should run 262 times.

Else

v = Application.Match(.Value, Sheets("Locations").Range("A2:A263"), 0)
If IsNumeric(v) Then
.Value = Sheets("Locations").Range("A2:A263").Cells(v + 1, 1).Value
Else
.Value = ""
End If
End If
'
I think the suggested "wait for refresh" command should go here. Before being copied and pasted into another worksheet as below. Currently on selected cell in the other worksheet worksheet but would prefer it pointed to '2018' B3.
Windows("Ecc vs S4.xlsx").Activate
Range("G1:G4").Select
Selection.Copy
Windows("Reconciliation 2 Progress Tracker.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Selection.Offset(1, 0).Select
'
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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