Hi billgyrotech,
You need construction like:
Try code like the following (tested and working):
Additional Comments:
a. It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
b. If you indent the code (it takes a lot of work), it is easier for you and for others to read, and is easier to maintain.
c. Instead of using 'Module1', 'Module2', etc, if you rename the modules, it may be easier to find the code:
In Excel VBA, change the name of Module1 or any module to something that means something to you as follows:
a. Click on any cell in the Excel Spreadsheet.
b. ALT-F11 to get to VBA.
c. CTRL-R to get project explorer (if it isn't already showing).
d. F4 to get the 'Properties' Window.
e. Left Click on the module you want to rename in the 'Project Explorer'.
f. In the Properties Window, next to '(Name)', change the name as required.
d. Debugger Secrets:
a. Press 'F8' to single step (goes into subroutines and functions).
b. Press SHIFT 'F8' to single step OVER subroutines and functions.
c. Press CTRL 'F8' to stop at the line where the cursor is.
d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
output to the IMMEDIATE WINDOW.
f. Select View > Locals to see all variables while debugging.
g. To automatically set a BREAKPOINT at a certain location put in the line:
'Debug.Assert False'
h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
if i >= 20 and xTV20 > 99.56 then
Debug.Assert False
endif
i. A variable value will be displayed by putting the cursor over the variable name.
e. In the future, if your workbook is password protected, you will get more responses if you post the password in the thread. I almost gave up, but found the password in the VBA code.
I hope all this helps.
Lewis
Bookmarks