I'm trying to create an Excel VBA script which will take 2 columns as input and output the values of into a text file.
e.g
A1: 123 B1: avenue
A2:231 B2: another lane
I'm after an output in a txt file that looks something like this:
House number: 123 Street name: avenue
----.
House number: 231 Street name: another lane
----.
Basically what i'm looking for is: "House number: "+A1+ " Street name: "+B2 "------"
I've got this to work with just 1 column however I'm stuck with adding a second.
Sub CreatetestScript()
If Dir("C:\test.txt") <> "" Then
Kill ("C:\test.txt")
End If
Sheets("test").Select
Dim acolumn As String
r = 2
Do While Cells(r, 1) <> ""
acolumn = Cells(r, 1).Value
run (Cells(r, 1))
r = r + 1
Loop
End Sub
Sub run(ByVal acolumn As String)
Dim fileName As String
fileName = "C:\test.txt"
Open fileName For Append As #1
Print #1, ""
Print #1, "House Number = " + acolumn
Print #1, "--------------"
Close #1
End Sub
Any help would be appreciated