Try:
Option Explicit
Const lFormColumn As Long = 10
Sub GenerateForm()
Dim c As Range
Dim cA As Range
Dim cB As Range
Dim i As Integer
Set c = Columns(1).Find("Shipped to")
WriteToForm String(18, "-")
WriteToForm "::Shipped To::"
WriteToForm String(18, "-")
If Not c Is Nothing Then
For Each cB In Intersect(c.CurrentRegion, Columns(2)).Cells
If Not cB.Row = 1 And Not cB.Value = "" Then WriteToForm cB.Value
Next cB
End If
Set c = Columns(1).Find("Contents Shipped")
WriteToForm Chr(1)
WriteToForm String(18, "-")
WriteToForm "::Contents Shipped::"
WriteToForm String(18, "-")
If Not c Is Nothing Then
For Each cB In Intersect(c.CurrentRegion, Columns(2)).Cells
WriteToForm cB.Value
For i = 1 To 4
WriteToForm "- " & Cells(1, i + 2).Value & ": " & NullNA(cB.Offset(0, i).Value)
Next i
Next cB
End If
End Sub
Function WriteToForm(ByVal s As String)
Dim i As Integer
i = Abs(Application.CountA(Columns(lFormColumn)) > 0)
If s = "" Then s = "N/A"
Cells(Rows.Count, lFormColumn).End(xlUp).Offset(i, 0).Value = s
End Function
Function NullNA(ByVal s As String)
If s = "" Then
NullNA = "N/A"
Else
NullNA = s
End If
End Function
Bookmarks