Sub ExportToTextFile()
Dim ws As Worksheet
Dim rng As Range
Dim txtFile As String
Dim r As Long, c As Long
Dim txt As String
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change to your sheet name
' Set the range
Set rng = ws.Range("A1:H6") ' Change to your range
' Define the text file path
txtFile = "D:\output.txt" ' Change to your path
' Open the text file in write mode
Open txtFile For Output As #1
' Loop through each row
For c = 1 To rng.Columns.Count Step 2
' Loop through each column pair
For r = 1 To rng.Rows.Count
' Write the cell values to the text file
txt = rng.Cells(r, c).Value & " " & rng.Cells(r, c + 1).Value
Print #1, txt
Next r
Next c
' Close the text file
Close #1
MsgBox "Data exported to text file successfully!", vbInformation
End Sub