1: Dim <--if you are to set a variable, you have to specify what kind of variable it is.
dim <variablename> as <variabletype> , e.g. "dim test as string" tells the program that this variable will contain text
2: Set <-- set <object> = <somevalue> you can set variables as objects that you don't know what is.
a range for example is neither a string or an integer, but an array. you could probably "dim r as range, r = range(a1:a4)", but setting it to an object is imho safer when it comes to runtime errors.
3:that is correct. a range is a selection of cells between the points you specify. for examle range("A1:B3") = all cells in this area in your sheet.
4: a messagebox is simply a box that pops up with information to the user. great for programming, as you could do a msgbox(yourvariable) <--to see that it is correct.
you have another option called inputbox where the user can insert information that your program can store in a variable for later use etc.
5: vbnullstring is not the same as "0". "0" is a value, whereas vbnullstring is nothing.
there is a difference. you could alternatively type "if <variable> is nothing then" or 'if <variable> = ""' for strings, but vbnullstring is the safest bet.
--------------
for your other questions
early in my code, I specify a range in R (set R = range(xxx))
R.select simply invokes that range. I could alternatively type Range(xxx).select <--but it's easiert to specify the range in a variable
--------------
setting variables later on in the macro.. why?
in short: trial and error.. I set the variables as I go.
From a programatically point of view, you could think of it like this: every variable you declare reserves a lil-bit of memory on your computer.
the 'foundrange' variable is declared only IF the user inputs a valid item to search for.
Why declare a variable and reserve memory-space if it's not needed?
however to be consistent with this rule, the "userchange" variable should also be set later on in the macro.
-------------
Exit sub.
Exit sub is not the same as End sub.
The code runs linear, and goes through each line of code from top to bottom. if an error comes along (like the user input is wrong) then it should exit the whole subroutine. or else it would continue trying to execute code with bad parameters.
as you can see in my code, the 'exit sub's are always in IF statements. what does that mean? well
Oh..
I assume your original problem is solved, so please click EDIT in your original (first) post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
(note: your thread will not be closed, so you can continue to post here and ask questions )
Bookmarks