Print out lines based on field value

neuro1

New Member
Joined
Sep 9, 2022
Messages
8
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Hi, I am trying to figure out how to print a line based on if the cell value = 'y'. I thought I can use switch statment as there is about 40 rows that I need to check if column 'J' is set to 'y' in the cell. If it does that I need to print the line or skip if it is set to 'n'.

Would I use a if statement to accomplish this?

Thanks



Below is my code and screenshot (column J):
Capture.JPG


VBA Code:
Sub CellsToFreedom()
  On Error GoTo ErrorHandler
  Dim freedomfile As String: freedomfile = ThisWorkbook.Path & "\FromTemplate.txt"
  Dim fso As Scripting.FileSystemObject: Set fso = New Scripting.FileSystemObject: Dim ts As Scripting.TextStream
  Set ts = fso.OpenTextFile(freedomfile, ForWriting, True)
  Dim tmp As String, pd As String, jd As String, source As String
  
tmp = tmp & MakeLine(Cells(6, 1).Value & Cells(6, 2) & Cells(6, 3) & Cells(6, 4).Value & "00", source & "" & pd, Cells(6, 6).Value)
ts.Write (tmp)
  MsgBox "Freedom file was created."
  writelog "file was created."
ExitHere:
  ts.Close
  Exit Sub
ErrorHandler:
  writelog Err.Description & "  " & Err.Number, "CellsToFreedom()", False
  Resume ExitHere
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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