Variable number of variables in VBA

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
364
Office Version
  1. 2019
As part of a macro, I'd like to run a form of error checking on sales orders. Basically, if the quantity of an order is not a whole number, then there's been an error in upstream processing. I'd like to keep a list of these problem orders, to display in a message box at the end of the macro. Something like "There were errors with orders #1839, #1923, #1934"

How do I handle the variable declarations and use as the errors are found?
I'm thinking something like the first error encountered is allocated to varError1, the second to varError2 and so on. I'd need some kind of incremental count of the number of errors.
The end result in the above example would see varError1=1839, varError2=1923 and varError3=1934
 

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.
As part of a macro, I'd like to run a form of error checking on sales orders. Basically, if the quantity of an order is not a whole number, then there's been an error in upstream processing. I'd like to keep a list of these problem orders, to display in a message box at the end of the macro. Something like "There were errors with orders #1839, #1923, #1934"

How do I handle the variable declarations and use as the errors are found?
I'm thinking something like the first error encountered is allocated to varError1, the second to varError2 and so on. I'd need some kind of incremental count of the number of errors.
The end result in the above example would see varError1=1839, varError2=1923 and varError3=1934
What do you want to do with this list of errors?
 
Upvote 0
Hi, you could either store the error order numbers in an array variable, which you could then Join() together to display in a Msgbox. Or if you really only want to display them in a message box you could just keep concatenating the error order numbers to an existing string variable as you come across them with an appropriate delimiter.
 
Upvote 0
Solution
Hi, you could either store the error order numbers in an array variable, which you could then Join() together to display in a Msgbox. Or if you really only want to display them in a message box you could just keep concatenating the error order numbers to an existing string variable as you come across them with an appropriate delimiter.
Thanks. I think the latter approach will work.

The error is only an error after some upstream calculation in the macro (prior to the calculation it's impossible to tell it's an error), hence I can't filter because I don't know yet if there's any errors.
Unfortunately, I need to just write the orders down and go back into the source data file to manually work out what has happened to cause the error.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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