Intermittent code issue when setting variable to cell value

frank_AL

Active Member
Joined
Oct 30, 2015
Messages
467
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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