KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 378
- Office Version
- 2016
- Platform
- Windows
Hello
I have a challenge.
I use this VBA code to print different pages and I put X next to the sheet name that I like to be printed in the sheets Stamdata (yellow) see picture 1. It works as it shall. Now I would like to insert 2 new sheets (red) before the sheets Stamdata (yellow) see image 2. But then the VBA code does not work, it does not follow the X.
Any help will be appreciated.
Best Regards
Klaus W
I have a challenge.
I use this VBA code to print different pages and I put X next to the sheet name that I like to be printed in the sheets Stamdata (yellow) see picture 1. It works as it shall. Now I would like to insert 2 new sheets (red) before the sheets Stamdata (yellow) see image 2. But then the VBA code does not work, it does not follow the X.
Any help will be appreciated.
Best Regards
Klaus W
VBA Code:
Sub Rektangelafrundedehjørner4_Klik()
Dim intRaekke As Integer
Dim SidsteSide As Integer
Dim SiderUdskrevet As Integer
SiderUdskrevet = 0
On Error GoTo fejl:
If Worksheets.Count < 1 Then
MsgBox "Der er ingen sider at udskrive?"
End If
For intRaekke = 5 To Worksheets.Count '<--Rettet til 5. Print første
'Tilføjet - 2 for at læse X fra række 3 i Stamdata
If Cells(intRaekke - 2, 2).Value = "x" Or _
Cells(intRaekke - 2, 2).Value = "X" Then
SidsteSide = Sheets(intRaekke).Range("G1")
If Not (IsNumeric(SidsteSide)) Or SidsteSide = 0 Then
MsgBox Worksheets(intRaekke).Name & " Celle G1 Er ikke et tal eller > 0?"
Exit Sub
End If
Sheets(intRaekke).PrintOut From:=1, To:=SidsteSide
SiderUdskrevet = SiderUdskrevet + 1
End If
Next
If SiderUdskrevet = 0 Then
MsgBox "Ingen sider valgt til udskrift."
End If
fejl:
If Err.Number = 1004 Then
MsgBox "Du skal indtaste et tal på Fane" & intRaekke & " celle G1"
End If
End Sub