Function RangeName(sName As String) As String
RangeName = Application.Substitute(sName, " ", "_")
End Function
Sub Printselected()
'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
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(6, 8) = selected Then
selected = 0
wsForm.PrintOut
Exit Sub
End If
End If
Next
End With
End Sub
Sub PrintMySelectedRange()
'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 Worksheets("2012").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
For r = 2 To wsData.Rows.Count
If Not wsData.Cells(r, 1).EntireRow.Hidden And wsData.Cells(r, 1).Value > 0 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(6, 8) = selected Then
selected = 0
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:="W:\Kpi\Technical Office\Hold Log\Hold Notices\2019" & Range("H6").Value, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Exit Sub
End With
End If
End If
Next
End With
' MsgBox ("selected range")
' MsgBox (Worksheets("2012").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count)
End Sub