Loop Macro

zinah

Active Member
Joined
Nov 28, 2018
Messages
368
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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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:

[TABLE="width: 384"]
<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 64"]V12:Z32[/TD]
[TD="class: xl64, width: 64"]EeID[/TD]
[TD="class: xl65, width: 64"]LAST NAME[/TD]
[TD="class: xl65, width: 64"]ORG LAYER[/TD]
[TD="class: xl65, width: 64"]SUPV[/TD]
[TD="class: xl65, width: 64"]LOCATION[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]11111[/TD]
[TD="class: xl66"]QQ[/TD]
[TD="class: xl67"]4[/TD]
[TD="class: xl68"]NNNN[/TD]
[TD="class: xl68, align: right"]123[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]22222[/TD]
[TD="class: xl66"]AA[/TD]
[TD="class: xl67"]4[/TD]
[TD="class: xl68"]GGGG[/TD]
[TD="class: xl68, align: right"]125[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]33333[/TD]
[TD="class: xl66"]BBB[/TD]
[TD="class: xl67"]4[/TD]
[TD="class: xl68"]CCC[/TD]
[TD="class: xl68, align: right"]127[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]44444[/TD]
[TD="class: xl66"]CCC[/TD]
[TD="class: xl67"]4[/TD]
[TD="class: xl68"]HHHH[/TD]
[TD="class: xl68, align: right"]129[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]555555[/TD]
[TD="class: xl66"]DDD[/TD]
[TD="class: xl67"]4[/TD]
[TD="class: xl68"]LLLLL[/TD]
[TD="class: xl68, align: right"]131[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]666666[/TD]
[TD="class: xl66"]EEE[/TD]
[TD="class: xl67"]5[/TD]
[TD="class: xl68"]HHHH[/TD]
[TD="class: xl68, align: right"]133[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]777777[/TD]
[TD="class: xl66"]FFF[/TD]
[TD="class: xl67"]5[/TD]
[TD="class: xl68"]LLLLL[/TD]
[TD="class: xl68, align: right"]135[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]88888[/TD]
[TD="class: xl66"]HHHH[/TD]
[TD="class: xl67"]5[/TD]
[TD="class: xl68"]CCC[/TD]
[TD="class: xl68, align: right"]137[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]99999[/TD]
[TD="class: xl66"]OOO[/TD]
[TD="class: xl67"]5[/TD]
[TD="class: xl68"]OKoKKK[/TD]
[TD="class: xl68, align: right"]139[/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[TD="class: xl66"]101010[/TD]
[TD="class: xl66"]LLL[/TD]
[TD="class: xl67"]5[/TD]
[TD="class: xl68"]HHHH[/TD]
[TD="class: xl68, align: right"]141

[/TD]
[/TR]
</tbody>[/TABLE]

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,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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