christopherlewis1620
New Member
- Joined
- Oct 26, 2020
- Messages
- 7
- Office Version
- 365
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
- Platform
- Windows
Hi All ,
i have a requirment to save the text in cells of the columns a text file , each cell has text and the same has to be saved. the file name is maintained in in column c , i have the below macro which does the work , but it uses the rownum, instead i want to specify from which column it should start the rownum for file name. can anyone help , i am new to vba and wanted some guidance here.
Option Explicit
i have a requirment to save the text in cells of the columns a text file , each cell has text and the same has to be saved. the file name is maintained in in column c , i have the below macro which does the work , but it uses the rownum, instead i want to specify from which column it should start the rownum for file name. can anyone help , i am new to vba and wanted some guidance here.
Option Explicit
VBA Code:
Sub WriteText()
Dim firstrow As Integer, RowNum As Integer, colnum As Integer
Dim filename As String
Dim Filelocation As String
Dim ws As Worksheet
Dim myValue As Variant
Dim rn As Range
myValue = InputBox("Give me some input")
Set ws = Worksheets("Sheet1")
Filelocation = "C:\Users\Clewis\Desktop\test\"
With ws
RowNum = 3
While .Cells(RowNum, 1) <> ""
filename = .Cells(RowNum, 1).Value
Open (Filelocation & filename & ".txt") For Output As #1
colnum = 4
While .Cells(RowNum, colnum) <> 0
Print #1, ws.Cells(RowNum, colnum) & " ";
colnum = colnum + 1
Wend
Close #1
RowNum = RowNum + 1
Wend
End With
End Sub
Last edited by a moderator: