Loop Macro

zinah

Active Member
Joined
Nov 28, 2018
Messages
355
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a table that has dynamic range and I need to set a loop macro to generate PPTX, I have all the macros but I'm struggling with how to write the loop macro:

These are the macros:

This macro generate all employees under this manager:

Code:
Call reset_List_Leader_Organization

Dim rSht As Worksheet
Dim dSht As Worksheet
    Set dSht = Sheets("Manipulated_Data")
    Set rSht = Sheets("Role Scorecard")


Dim lastR As Long
    lastR = dSht.Cells(Rows.Count, 1).End(xlUp).Row


Dim eeid, lnm, ol, loc, supv, oLead, reg, nhrly As String
    eeid = rSht.[Z5].Value
    lnm = rSht.[Z6].Value
    ol = rSht.[Z7].Value
    loc = rSht.[Z8].Value
    supv = rSht.[Z9].Value
    oLead = "Level " & rSht.[Y8].Value & " Manager ID"


Dim eeidC, lnmC, olC, locC, supvC, oLeadC, regC, nhrlyC As Integer
    eeidC = Application.WorksheetFunction.Match(eeid, dSht.[1:1], 0)
    lnmC = Application.WorksheetFunction.Match(lnm, dSht.[1:1], 0)
    olC = Application.WorksheetFunction.Match(ol, dSht.[1:1], 0)
    locC = Application.WorksheetFunction.Match(loc, dSht.[1:1], 0)
    supvC = Application.WorksheetFunction.Match(supv, dSht.[1:1], 0)
    oLeadC = Application.WorksheetFunction.Match(oLead, dSht.[1:1], 0)
    regC = Application.WorksheetFunction.Match("Regular Employee", dSht.[1:1], 0)
    nhrlyC = Application.WorksheetFunction.Match("Ee Type", dSht.[1:1], 0)




Dim i, j As Integer
    j = rSht.[V13].Row
    
For i = 1 To lastR
    If dSht.Cells(i, regC).Value = True Then
        If UCase(dSht.Cells(i, nhrlyC).Value) = UCase("Non-Hourly") Then
            If Format(dSht.Cells(i, oLeadC).Value, "0") = Format(rSht.[W8].Value, "0") Then
                If dSht.Cells(i, olC).Value <= rSht.[Y8].Value + 2 Then
                    j = j + 1
                    rSht.Cells(j, [V13].Column).Value = dSht.Cells(i, eeidC).Value
                    rSht.Cells(j, [W13].Column).Value = dSht.Cells(i, lnmC).Value
                    rSht.Cells(j, [X13].Column).Value = dSht.Cells(i, olC).Value
                    rSht.Cells(j, [Y13].Column).Value = dSht.Cells(i, supvC).Value
                    rSht.Cells(j, [Z13].Column).Value = dSht.Cells(i, locC).Value
                End If
            End If
        End If
    End If
Next i


rSht.[U12].Value = "V12:Z" & j


Call sort_List_Leader_Organization

What I need is a loop macro that can loop into all the generated data from above macro to generate the pptx
I have Employee ID that is under drop-down list and I named the range as [ID_Layer3_4]
Code:
Sheets("Org_Layer").[ID_Layer3_4]

Once this loop finished then I can call all the macros that can generate the PPTX


Does that make sense? I'm ready to provide more details or clarify more.


Thank you!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What is it you need to loop through exactly?
 
Upvote 0
I need the it to loop through below table that it's generated from the macro I shared in my first post:

V12:Z32EeIDLAST NAMEORG LAYERSUPVLOCATION
11111QQ4NNNN123
22222AA4GGGG125
33333BBB4CCC127
44444CCC4HHHH129
555555DDD4LLLLL131
666666EEE5HHHH133
777777FFF5LLLLL135
88888HHHH5CCC137
99999OOO5OKoKKK139
101010LLL5HHHH141


<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>
</tbody>

And the range V12:Z32 is dynamic which depends on number of generated rows that macro in post one generates.
 
Upvote 0

Forum statistics

Threads
1,215,904
Messages
6,127,654
Members
449,395
Latest member
Perdi

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