Output to Text File based on Values

dhosi439

Board Regular
Joined
May 13, 2009
Messages
62
I have a spreadsheet with data starting in column B row 11. Column C users input an X based on the data in column B they want in the text file.

For example:

Column B has data from row 11 to row 50, the user inputs X into Column C for each value in Column B that they want. Then by clicking a command button, all the information in column B that has a corresponding X in column C will be written to a text file.

Note: The range in column B can vary. There can be several hundred entries.

Any help with this would be appreciated.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try:

Code:
Sub WriteToFile()
Dim objFSO As Object
Dim objOutputFile As Object
Dim rngCell As Range
Dim lngLastRow As Long
lngLastRow = Cells(Rows.Count, 2).End(xlUp).Row
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\Output.txt") ' change file path/name as required
For Each rngCell In Range("B11:B" & lngLastRow)
    If rngCell.Offset(0, 1) = "X" Then objOutputFile.writeline rngCell.Value
Next rngCell
End Sub

Dom
 
Upvote 0
This was perfect, allowed to change some other code to run a bit more efficiently as well. Thanks for the fast response as well.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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