Hi All,
I have one spreadsheet set up with a form detailed within the sheet using VBA and name manager to print data onto the form and save as a pdf. However I took the sheet and created a new one for a different purpose changing the form and all of the names in name manager to match the data I wanted in each section of the form but now when I press the print button within the sheet or save selected I get the error code 1004 Method "Range" of object global failed with the range name highlighted in yellow. How can I fix this error to make the sheet work?
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Printselected()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'set up your merge form by naming the merge fields _
with the same name as the data fields you are importing.
Dim wsForm As Worksheet, wsData As Worksheet
Dim sRngName As String, r As Long, c As Integer
Dim selected As String
selected = InputBox("Enter Ref number", "Print Single Sheet")
Set wsForm = Worksheets("Form") 'change to your sheet name of the form
Set wsData = Worksheets("2019") 'change to your sheet name with Data in
With wsData.Cells(1, 1).CurrentRegion
For r = 2 To .Rows.Count[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
If Not wsData.Cells(r, 1).EntireRow.Hidden Then
For c = 1 To .Columns.Count
sRngName = wsData.Cells(1, c).Value
Range(RangeName(sRngName)).Value = wsData.Cells(r, c)
Next
If wsForm.Cells(2, 2) = selected Then
selected = 0
wsForm.PrintOut
Exit Sub
End If
[/FONT]
I have one spreadsheet set up with a form detailed within the sheet using VBA and name manager to print data onto the form and save as a pdf. However I took the sheet and created a new one for a different purpose changing the form and all of the names in name manager to match the data I wanted in each section of the form but now when I press the print button within the sheet or save selected I get the error code 1004 Method "Range" of object global failed with the range name highlighted in yellow. How can I fix this error to make the sheet work?
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Printselected()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'set up your merge form by naming the merge fields _
with the same name as the data fields you are importing.
Dim wsForm As Worksheet, wsData As Worksheet
Dim sRngName As String, r As Long, c As Integer
Dim selected As String
selected = InputBox("Enter Ref number", "Print Single Sheet")
Set wsForm = Worksheets("Form") 'change to your sheet name of the form
Set wsData = Worksheets("2019") 'change to your sheet name with Data in
With wsData.Cells(1, 1).CurrentRegion
For r = 2 To .Rows.Count[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
If Not wsData.Cells(r, 1).EntireRow.Hidden Then
For c = 1 To .Columns.Count
sRngName = wsData.Cells(1, c).Value
Range(RangeName(sRngName)).Value = wsData.Cells(r, c)
Next
If wsForm.Cells(2, 2) = selected Then
selected = 0
wsForm.PrintOut
Exit Sub
End If
[/FONT]