Macro to Print NON-BLANK Cells from Column A

moe10134

Board Regular
Joined
Sep 8, 2005
Messages
162
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I have a macro that is designed to print all text from Column A to print a list of all data except the blank cells. This is my macro, but it is not printing.

I have it assigned to a Command Button. Is the print menu supposed to pop up or will it just print to my default printer?

Is this the correct macro to use? When I execute it I don't get any error, but it just won't print anything at all.

Can someone please help? Or Create a new macro that will print only the text as a list of non-blank cells?

Thanks much,
MOE10134


Private Sub CommandButton1_Click()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = Application.DefaultFilePath & "\NumeroChamados.txt"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1 , cellValue,
Else
Print #1 , cellValue,
End If
Next j
Next i
Close #1


End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
This macro works and exports to a text file correctly. I need to add a seperatine that will remove all the spaces from the text being exported to give me a .txt file with just text, no spaces. I also need to specify a specific worksheet named "Output Linking" and a range of cells (A1:A3000) or a reference to only select Column A in the Output Linking tab. Can anyone edit this seperatine to 1. Be designated to a specific worksheet and range or column in the sheet. 2. Remove all the spaces from the exported text? Any assistance is appreciated!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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