vba copy cell value to text and check if value is numeric

Shawn1960

New Member
Joined
Jun 15, 2017
Messages
4
I have the following code, it some what redundant i think, wandering if there is a shorter way to accomplish this and check to see if the value being copied is numeric if it is not write a 0 otherwise copy the number in the cell
I write each row every minute from a rtd script
thanks shawn
Sub stock1()


Open "C:\users\shawn browne\desktop\stock\stock1.txt" For Append As #1
Print #1 , Now() & " ,";
Print #1 , Sheets(1).Range("a4") & ",";
Print #1 , Sheets(1).Range("b4") & ",";
Print #1 , Sheets(1).Range("c4") & ",";
Print #1 , Sheets(1).Range("d4") & ",";
Print #1 , Sheets(1).Range("e4") & ",";
Print #1 , Sheets(1).Range("f4") & ",";
Print #1 , Sheets(1).Range("g4") & ",";
Print #1 , Sheets(1).Range("h4") & ",";
Print #1 , Sheets(1).Range("i4") & ",";
Print #1 , Sheets(1).Range("j4") & ",";
Print #1 , Sheets(1).Range("k4") & ",";
Print #1 , Sheets(1).Range("l4") & ",";
Print #1 , Sheets(1).Range("m4") & ",";
Print #1 , Sheets(1).Range("n4") & ",";
Print #1 , Sheets(1).Range("o4") & ",";
Print #1 , Sheets(1).Range("p4") & ",";
Print #1 , Sheets(1).Range("q4") & ",";
Print #1 , Sheets(1).Range("r4") & ",";
Print #1 , Sheets(1).Range("s4") & vbCrLf;

Close #1
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If I understand correctly, all of those Print #1 code lines can be replaced by this single one...

Print #1 , Join(Evaluate("IF(ISNUMBER(A4:S4),A4:S4,0)"), ",") & vbCrLf
 
Upvote 0

Forum statistics

Threads
1,215,561
Messages
6,125,533
Members
449,236
Latest member
Afua

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