Macro run until empty (variable cell)

acurle

New Member
Joined
Feb 26, 2025
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

Hoping someone could help?
I'm just getting back into VBA and although I've managed to get quite far, I'm drawing a mind blank getting the end at variable table length.
I have a table (called "Mass_Doc_Run") where the length can be variable Sheets("Mass Doc Run"), columns A, B and C have data which is copy pasted into another sheet. There is then a corresponding IF statement depending upon the answer given within a cell to create a PDF and save down.
Can someone help with repeating the above until the table "Mass_Doc_Run" ends? This is variable length which is the bit which is causing me a problem.

Hope this makes sense - first time using a forum!

Thanks,
Alex

VBA Code:
Sub TEST()

    Sheets("Mass Doc Run").Select
    Range("A2").Select
    Selection.Copy
   
    Sheets("Template Control").Select
    Range("B6").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
    Sheets("Mass Doc Run").Select
    Range("B2").Select
    Selection.Copy
   
    Sheets("Template Control").Select
    Range("B8").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    Sheets("Mass Doc Run").Select
    Range("C2").Select
    Selection.Copy
   
    Sheets("Template Control").Select
    Range("B9").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    If Sheets("Template Control").Range("B9").Value = "POC" Then
   
        Sheets("Proof of Compliance (POC)").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        Sheets("Template Control").Range("B1").Text, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
       
    ElseIf Sheets("Template Control").Range("B9").Value = "POS" Then
   
        Sheets("Proof of Sustainability (POS)").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        Sheets("Template Control").Range("B1").Text, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
       
    End If
   
       
    
End Sub
 
Hi Alex

I hope this is what you meant.
VBA Code:
Sub TEST()
    Dim lastRow As Long, i As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To lastRow
        Sheets("Template Control").Range("B6").Value = Sheets("Mass Doc Run").Range("A" & i).Value2
        Sheets("Template Control").Range("B8").Value = Sheets("Mass Doc Run").Range("B" & i).Value2
        Sheets("Template Control").Range("B9").Value = Sheets("Mass Doc Run").Range("C" & i).Value2
        
        If Sheets("Template Control").Range("B9").Value = "POC" Then
            Sheets("Proof of Compliance (POC)").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            Sheets("Template Control").Range("B1").Text, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=False
        End If
    Next i
End Sub
 
Upvote 0

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