I have been having difficulty being able to combine the text in the applicable row from columns 8 to lastRow into one text string that will then be written to a file. The line I am stuck on is F$I also want to round the values in those cells to be 3 digits long. Please help me figure out my error and clean this up. Thank you.
Set WS = Worksheets(1)
Pin = InputBox("What is the project pin?", _
"File Location by Pin Number", "12345")
MyPath = "C:\pin\" & Pin
StartStation = InputBox("What station does the project start at?", _
"Station by 50ft increments", "1000")
Direction = InputBox("Upchain(50) or Downchain(-50)?", _
"Direction", "50")
With WS
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
FF = FreeFile
Open MyPath & "_" & Direction & ".txt" For Output As #FF
Print #FF, Pin & " 111042915A 482C1 50 23008823 500000000 " & StartStation
For A = 2 To LastRow 'label rows as A, A=1 at row 2
i = 0
If .Cells(A, 5) > 0 Then
For B = 8 To LastCol 'label columns as B, B=1 at column H
Offset = .Cells(1, B) - .Cells(1, 8)
If .Cells(2, B) <> "" Then
C$ = "2 " & StartStation
D$ = "3 1"
E$ = "5 1"
Set rang = Range(.Cells(A, 8), .Cells(A, B))
CurSta = StartStation + (Direction * i)
F$ = "G " & CurSta & " 65 0999" _
& combine(rang, "")
G$ = "B 1"
Print #FF, C$
Print #FF, D$
Print #FF, E$
Print #FF, F$
Print #FF, G$
End If
Next
End If
i = i + 1
Next
Close #FF
End With
Function combine(rng As Range, Optional delim As String = "") As String
combine = Join(Application.Transpose(Application.Transpose(rng)), delim)
End Function
Bookmarks