Hey guys, I'm quite new to excel VBA and I need some help with looping
Here's what I have so far
Ok, basically, this is the top part of my codes. It generates a report which are new sheets in the same workbook.
So this loops checks the parameters and calculates the necessary calculation and writes out the report. Once it reaches an empty cell it will stop.
Now, the code above generates the June report, taking in parameters from cells B1, B2, B3 and so on.
So when this loop is done, I want it to move to C1, C2, C3 etc. And then after that is done, D1, D2, D3 and so on and so forth until it reaches and empty cell.
I'm thinking of a For.. Next loop but I can't get it to work.
Any ideas?
Thanks
Here's what I have so far
Sub gendata()
'do while loop loops through gendata until it reaches an empty cell
Do
'required parameters
mth = Sheets("Info").Range("B1").Value
srcFile = Sheets("Info").Range("B2").Value
rowPerHr = Sheets("Info").Range("B3").Value
stStart = Sheets("Info").Range("B4").Value
oilStart = Sheets("Info").Range("B5").Value
otherStart = Sheets("Info").Range("B6").Value
allStart = Sheets("Info").Range("B7").Value
'add a new worksheet
Worksheets.Add().Name = mth
'fill in the data
Call draw_table(1, 1, "ST Job")
Call draw_table(31, 1, "Oil Job")
Call draw_table(61, 1, "Other Job")
Call draw_table(91, 1, "Total Job")
'ST Job
Call gen_section(mth, srcFile, stStart, 3, rowPerHr)
'Oil Job
Call gen_section(mth, srcFile, oilStart, 33, rowPerHr)
'Other Job
Call gen_section(mth, srcFile, otherStart, 63, rowPerHr)
'All Job
Call gen_section(mth, srcFile, allStart, 93, rowPerHr)
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
Ok, basically, this is the top part of my codes. It generates a report which are new sheets in the same workbook.
So this loops checks the parameters and calculates the necessary calculation and writes out the report. Once it reaches an empty cell it will stop.
Now, the code above generates the June report, taking in parameters from cells B1, B2, B3 and so on.
So when this loop is done, I want it to move to C1, C2, C3 etc. And then after that is done, D1, D2, D3 and so on and so forth until it reaches and empty cell.
I'm thinking of a For.. Next loop but I can't get it to work.
Any ideas?
Thanks