writetotext

Joined
Oct 26, 2020
Messages
7
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. 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


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:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top