How to repeat vba code to use next row down

Virkis

New Member
Joined
Aug 29, 2018
Messages
1
Hello, I am new to vba coding so apologises if this is a very basic question!

I am writing a macro that will generate a .zrxp file on which is written the following (from the Active Worksheet):

Print #1 , "#REXCHANGE"; Range("A3").Value; "|*|RINVAL-777|*|"
Print #1 , "#LAYOUT(timestamp,value,remark)|*|"

Print #1 , (Format(Range("B3").Value, "yyyymmdd")); (Format(Range("c3").Value, "hhmm")); ", station visit by "; Range("O3"); ", Gauge "; Range("D3"); " ,Logger "; Range("H3"); ", "; Range("I3")

I would now like to repeat the above and write to the same .zrxp file (without overwriting the above) but based on information from the row below in the Active Sheet. For example:

Print #1 , "#REXCHANGE"; Range("A4").Value; "|*|RINVAL-777|*|"
Print #1 , "#LAYOUT(timestamp,value,remark)|*|"

Print #1 , (Format(Range("B4").Value, "yyyymmdd")); (Format(Range("c4").Value, "hhmm")); ", station visit by "; Range("O4"); ", Gauge "; Range("D3"); " ,Logger "; Range("H4"); ", "; Range("I4")


I would like this to repeat for all rows in the Active Sheet until it reaches a row with no value in A. Then end and save.


Please forgive my ignorance! Any help would be greatly appreciated

V
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi there and welcome. This should do it:

Code:
Dim Lastrow As Long
Dim ThisRow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For ThisRow = 3 To Lastrow
    Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] , "#REXCHANGE"; Range("A" & ThisRow).Value; "|*|RINVAL-777|*|"
    Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] , "#LAYOUT(timestamp,value,remark)|*|"
    Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] , (Format(Range("B" & ThisRow).Value, "yyyymmdd")); (Format(Range("c" & ThisRow).Value, "hhmm")); ", station visit by "; Range("O" & ThisRow); ", Gauge "; Range("D3"); " ,Logger "; Range("H" & ThisRow); ", "; Range("I" & ThisRow)
Next ThisRow

If you also meant to pick up the gauge row by row, then replace the "D3" with "D"&ThisRow.

Regards
John
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,844
Messages
6,127,252
Members
449,372
Latest member
charlottedv

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