Making a notepad text file from select spreadsheet cells but eliminating empty cells causing spaces in the text file.

jaystub

New Member
Joined
Nov 12, 2017
Messages
6
I'm currently using a VBA macro to gather cell data and transfer the data to a notepad text file. My macro works great but unfortunately if a cell is empty the notepad will add space to the text file. How can I eliminate the empty cells causing spaces in the text file?

My current macro is as follows:

Sub data_out_save_S1414()
Dim iCntr
Dim strFile_Path As String
strFile_Path = Range("fo1")
Open strFile_Path For Output As #1
For iCntr = 5 To 1514
Print #1 , Range("h" & iCntr)
Next iCntr
Close #1
CreateObject("WScript.Shell").Popup "Your data is now saved as a NotePad file.", 3
End Sub


Thank you in advance for your ideals or suggestions.

"Bubba"
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this.
Rich (BB code):
Sub data_out_save_S1414()
Dim iCntr As Long
Dim strFile_Path As String

    strFile_Path = Range("fo1")
    
    Open strFile_Path For Output As #1 
        For iCntr = 5 To 1514
            If Range("H" & iCntr).Value <> "" Then
                Print #1 , Range("h" & iCntr)
            End If
        Next iCntr
    Close #1 
    
    CreateObject("WScript.Shell").Popup "Your data is now saved as a NotePad file.", 3
    
End Sub
 
Upvote 0
Norie,
Thank you for your help. Your application helped me understand my mistake on this. I modified your line below:

If Range("H" & iCntr).Value <> "" Then

to

If Range("H" & iCntr).Value <> " " Then

It was not working until I added the space between the quotes.

Many thanks for your assistance.

Sincerely,
"Bubba"
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,961
Members
452,539
Latest member
delvey

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