Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

simon rogue

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Simon - the rogue '-1'

Simon - the rogue '-1'

ResolvedVersion 2007

Jen has attended:
Excel VBA Intro Intermediate course

Simon - the rogue '-1'

Simon, could you please have a think about how to explain the -1 in the code for mark ups and commission. Would like to know out of interest/to avoid this problem if I am writing code in the future. Thanks, Jen.

RE: Simon - the rogue '-1'

Hi Jen,

Thank for posting that question and welcome to the forum.

I have sinced realised this is a terrible way of doing the code and I have found it impossible to explain the -1 in a different way even after speaking to a friend.

The better way of doing it would be to start the Currentregion.count from 9 and then start the loop from two so it applies the functions from row 10 to the bottom. I think this method is more transparent and is easier to follow:

Sub CommMarkup()

Dim intColumn As Integer


intColumn = Sheets(strName).Range("a9").CurrentRegion.Columns.Count
'counts number of columns intcount = last column selling price
For intRowCount = 2 To Sheets(strName).Range("a9").CurrentRegion.Rows.Count
'In the next column after the last column(Selling Price)
'intcolumn is always referenced from the last column which at the time was Selling Price

'Apply the MarkUp function in the next blank column
'Markup arguments are DP followed by Selling Price

Sheets(strName).Range("a9").Cells(intRowCount, intColumn + 1) = _
MarkUp(Sheets(strName).Range("a9").Cells(intRowCount, intColumn - 1), _
Sheets(strName).Range("a9").Cells(intRowCount, intColumn))
'Apply the Commission formula using the Markup value created above
Sheets(strName).Range("a9").Cells(intRowCount, intColumn + 2) = _
Commission(Sheets(strName).Range("a9").Cells(intRowCount, intColumn + 1))

Next intRowCount ' increase the row number by one

Sheets(strName).Range("J9") = "Mark Up"
Sheets(strName).Range("K9") = "Commission"


End Sub

I hope this helps and sorry for the delay in responding.

Regards

Simon

Wed 28 Dec 2011: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Adding date and time

Here are two quick ways to add the date and time to your spreadsheet:

1) Type =NOW(), which displays both date and time in the same cell
or
2) Hold Ctrl and type the colon (:) into one cell for the date and the semi-colon(;)into another for the time.

Note that =NOW() updates to the current date/time whenever the spreadsheet recalculates.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.