Printing text from multiple worksheets to .txt

visual_basic_basic

New Member
Joined
Mar 19, 2015
Messages
1
I am currently working on a piece of VBA to output a list of headings and associated values with those headings to a .txt file. I currently have a set of headings and a set of values all in one worksheet and an excerpt of the working code is shown below:

Sub Print_To_File()
Open "C:\My_File.txt" For Output As #1
If Len(Cells(1, 7)) > 0 Then Print #1, Cells(1, 7) & Chr(13) + Chr(10)
If Len(Cells(24, 7)) > 0 Then Print #1, Cells(24, 1), Cells(24, 7)
If Len(Cells(25, 7)) > 0 Then Print #1, Cells(25, 1), Cells(25, 7)
If Len(Cells(26, 7)) > 0 Then Print #1, Cells(26, 1), Cells(26, 7)
If Len(Cells(27, 7)) > 0 Then Print #1, Cells(27, 1), Cells(27, 7)
If Len(Cells(28, 7)) > 0 Then Print #1, Cells(28, 1), Cells(28, 7)
Print #1, Chr(13) + Chr(10)

Essentially it is the bold line of text I would like to change, I need this to be changed from the original cell in worksheet 1 to a cell in worksheet 2 (lets say Cell A1) with the rest still being printed from worksheet 1.

This seems like there should be a really trivial solution but through various trial and error coupled with a lot of Googling I've drawn a blank.

Any help would be greatly appreciated! Thanks in advance.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,216,057
Messages
6,128,520
Members
449,456
Latest member
SammMcCandless

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