Combining Do Loops with other Macros statements

damien120

New Member
Joined
Feb 13, 2019
Messages
8
Hello all,

I am looking to make 1000+ reports based on a template. I have other sheets referencing the target city to update the data they report on. I have a master macro that calls on three other macros to format accordingly and save as "Location Report- Austin 1".

After creating the Austin report, I am looking to make one based out of the Dallas location. Thus I change the Target City to that all the other sheets will automatically update and then run the three macros (format and save file). My question is, how can I loop my macro so that it works its way down the 1,000+ cities. I am wondering if I can combine a Do Until statement and embed the other three macros within it.



City#Target#
Austin
1Austin1
Dallas2
Houston3
Chicago4
Miami5
Phoenix6
......
......

<tbody>
</tbody>


Thank you in advance and will greatly appreciate any guidance.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,536
This macro assumes the city names are in column A.
Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim city As Range
    For Each city In Range("A2", Range("A" & Rows.Count).End(xlUp))
        'your code here
    Next city
    Application.ScreenUpdating = True
End Sub
 

damien120

New Member
Joined
Feb 13, 2019
Messages
8
Thank you for mumps for the answer!

After the new city populates, I am trying to save the report. Following a naming convention so that the report is saved as "Austin 1". The code down below is what I added where you advised.

I am now getting a "Run-time error '1004'
Cannot access 'Austin 1.xlsm'

ActiveWorkbook.SaveAs Filename:="C:[File Path] & Range("C2").Text & Chr(32) & Range("D2").Text & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, Password:=vbNullString, WriteResPassword:=vbNullString, _
ReadOnlyRecommended:=False, CreateBackup:=False
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,536
It is difficult to suggest a solution without seeing your macros and how your workbook is organized. Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do using a few examples from your data and referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,536
Could you upload a version of your file that includes all the macros you are currently using?
 

Forum statistics

Threads
1,082,389
Messages
5,365,161
Members
400,827
Latest member
Mitzescu

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top