Loop until blank

bi2lel

New Member
Joined
Feb 28, 2021
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Hello guys, hope you're doing good
So my problem is i have a task at hand with complex features or codes. I found the codes seperately and every one works good but when I try to add them together the code does not work. I want to fill a template according to ce cells and print the template and save it as pdf. and I want it to loop until a blank cell from A2,A3,A4,......., until blank. So here are my codes
Print code:
VBA Code:
Sub print1()

'

' print1 Macro

' print 1 row without loop

'



'

Sheets("Feuil1").Select

Range("A2").Select

Selection.Copy

Sheets("canva").Select

ActiveSheet.Paste

ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _

:=True, IgnorePrintAreas:=False

End Sub

the save as pdf code:
VBA Code:
Sub SaveAsPDF()

'Saves active worksheet as pdf using concatenation

'of A2



Dim fName As String

With ActiveSheet

fName = .Range("A2").Value

.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

"C:\My Documents\" & fName, Quality:=xlQualityStandard, _

IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

End With

End Sub
 
Last edited by a moderator:
So you can try this part
VBA Code:
Sheets("Feuil1").Select
        x = Range("A" & n)
        Sheets("canva").Select
        Range("AD7") = "N:     " & "60/" & x
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
                                                                        :=True, IgnorePrintAreas:=False

then about
VBA Code:
fName = .Range("AD7").Value
file name as I can see
fNmae is N: 60/21???
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Miss typing sorry
It's merged cell not OK with VBA
What about the file name to be saved?
 
Upvote 0
fName is the value of "AD7"
not 60.
in "feuil1" it is from "A1" to infinit lets say "A500"
i want an inputmsgbox to select where to start like "40" then the code starts at "feuil1" "A40"
and inputmsgbox to select where to finish like "52" then the code stops at "A52"
I removed the merged cell in "AD7"
Thank you
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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