Copying cell values to a external file in VBA
Cracked it!
Sub Report_Body()
'Builds record 2's for pensions interface
Dim Cell_Loc As String
Dim Cell_Num As Integer
Dim Cell_Contents As String
Dim Output As String
Cell_Contents = 2
Cell_Num = 2
Do While Cell_Contents = "2"
Output = ""
Cell_Loc = "A" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "B" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "C" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "D" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "E" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "F" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "G" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "H" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "I" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "J" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "K" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "L" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "M" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "N" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "O" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "P" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "Q" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "R" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","
Cell_Loc = "S" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
' incroment counter by 1 and sets column two A ready for loop
Cell_Num = Cell_Num + 1
Cell_Loc = "A" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Print #1, Output
Loop
End Sub
|