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.
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.