Write a line every 10th row in text file

syedmk

New Member
Joined
Aug 14, 2008
Messages
22
Hi all,
I have multiple worksheets that starts from row 3 that I write to text to. Only 2 columns. But every 10th row I want to insert a different text as separator. I tried For statement with Step 11 but it prints more than required. But if I hard code the number like row = 11 or row = 21 or row = 31 and so on then it works except there is uncertainty of the amount for me to write the row = ?? statement.

My current code is

Code:
    Print #1, "     .WaitForEvent rcEnterPos, ""30"", ""0"", 7, 36"
    Print #1, "     .WaitForDisplayString ""126"", ""30"", 7, 25"
    Print #1, "     .TransmitANSI """ & Format(Replace(MyExtract(ws1.Name, 2, "B", " "), ".", "/"), "ddmmmyyyy") & stn & """"
    wsrowcnt = Range("A65536").End(xlUp).Row
 
    For wsrows = i To wsrowcnt
    Print #1, "     .TransmitANSI """ & Trim(Cells(wsrows, 1).Value) & Trim(Cells(wsrows, 2).Value) & """"
    Print #1, "     .TransmitTerminalKey rcIBMFieldPlusKey"
    If wsrowcnt - 2 > 10 Then
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
 
    If wsrows = 12 Or wsrows = 22 Or wsrows = 32 Or wsrows = 42 Then
    Print #1, "     .TransmitTerminalKey rcIBMPageDownKey"
    Print #1, "     .WaitForEvent rcKbdEnabled, ""30"", ""0"", 1, 1"
    Print #1, "     .WaitForEvent rcEnterPos, ""30"", ""0"", 7, 36"
    Print #1, "     .WaitForDisplayString ""126"", ""30"", 7, 25"
    Print #1, "     .TransmitTerminalKey rcIBMTabKey"
    Print #1, "     .TransmitTerminalKey rcIBMTabKey"
    Print #1, "     .TransmitTerminalKey rcIBMTabKey"
    Print #1, "     .TransmitTerminalKey rcIBMTabKey"
    End If
    End If
    Next wsrows

I would like to change that "If wsrows = wsrows 12 Or ..." statement to something dynamic that will write a line every 10th or 11th line in the text file. I am not sure the math calculation to do for this. Hope my explanation is clear?

Thanx in advance...
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Thank you sir! Works perfectly..!

so the mod result 0 is to divide all rows per block of 10 until finish?
 
Upvote 0
The If statement checks that (wsrows - 2) is exactly divisible by 10. So the code within it runs for every 10th row.
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

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