simon rogue
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

Simon - the rogue '-1'

resolvedResolved · Low Priority · Version 2007

replyReply Tue 13 Dec 2011, 16:36Delegate Jen said...

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.

For upcoming training course dates see: Pricing & availability

replyReply Wed 21 Dec 2011, 12:16Trainer Simon said...

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.

 

Please browse our web site to find out more about
microsoft excel courses and other Microsoft training courses.

Excel tip:

Hide columns in an Excel 2010 Worksheet

If you don’t want part of the Excel worksheet to be visible or when you don’t want certain data to appear in print outs, then a simple solution is to temporarily hide a column or multiple columns.

Hiding a single column:

1)Right click on the column header of the column you want to hide (this is the grey bar along the top edge of the worksheet)
2)Choose Hide from the menu
3)This column will now be hidden from view

Hide more than one column:

1)In the column header drag select to highlight the columns you want hidden
2)Right click and choose Hide from the menu

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard