Need help with looping

pyro77

New Member
Joined
Nov 16, 2008
Messages
20
Hey guys, I'm quite new to excel VBA and I need some help with looping

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 :)
 
Ah ok I see it now.

How about where Ravi coded
Code:
x = Sheets("info").Cells(1, Columns.Count).End(xlToLeft).Column
?

I found out that Dim a/x as Long is declaring the variables as Long.

This sets X = to the column number of the right most column before a blank (The same as selecting A1 then holding ctrl and pressing the right arrow)
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,225,483
Messages
6,185,263
Members
453,284
Latest member
osy25

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