Intermittent code issue when setting variable to cell value

frank_AL

Active Member
Joined
Oct 30, 2015
Messages
469
I have a code module that calculates monthly commission values. Some of the salesmen have shared accounts where 2 salesmen service a common account. In the database this is indicated by the SLS code (Column B) having 2 salesmen's initials separated by "/".
When this happens each salesman receives 1/2 of the commission for that record.

For example salesman FWB shares an account with salesman SRB. The SLS code for these entries would be FWB/SRB.
So salesman FWB would have entries where he is the sole salesman along with entries for the shared account.

In my code I test for this by using the INSTR function to see if "/" exists in the SLS code: If INSTR(cells(crow, "B"),"/") > 0
I have been validating the code module by taking one specific month and manually calculating the 91 records.
When I run my code module I am getting a different answer.

I added a variable called slscode and populated with the SLS code: slscode = Cells(crow, "B").Value
I changed the INSTR test to: If(INSTR(slscode, "/") > 0
So I put a break in the code for the INSTR line so I can determine if the code is identifying that the "/" exists.
What I am seeing is that in a few instances the slscode variable is EMPTY rather than being populated with the correct SLS code.
When this happens the commission for that record is added to the monthly total without being divided by 2
This results in the monthly total being incorrect.

When the slscode variable is EMPTY, I manually rerun that line of code and the variable is then accurately updated to the correct SLS code.

I am scheduled to meet with the client Monday and really need some help to get this resolved.
Has anyone encountered a similar issue or does anyone have a suggestion for getting this resolved?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Your problem no doubt is because:

Code:
Cells(crow, "B").Value

has no sheet qualifier. Lets say 'crow' equals 1. Which cell B1 do you refer to? There is a cell B1 on every single sheet of every single workbook. You need to be telling the code which B1 you refer to. eg

Code:
Sheets("Sheet1").Cells(crow, "B").Value

or you may even need to add a workbook qualifier too.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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