
This is how I would write your subroutine:ĭim i as Integer, X1 as Single, X2 as Single, Y1 as Single, Y2 as Single

This is why you should put any code which acts on Cells directly in the Worksheet objects module.If you would like to see a sample VBA Excel project, send me a PM, and I'll send you one. Also it looks like you set the initial value of a to be the letter o, instead of zero.Futhermore, referencing "Cells" in a Module isn't going to work, unless you provide more detailed referencing about which Worksheet you intend to act on.

So you would simply write: Cells(5 + i, 20) = Distance(X1, X2, X3, X4) Also here: Dim a 'Initialize Counting VariableĪ = o You should realize that not dimming a as an integer is a waste of memory as the default datatype is a variant. However, when you are assigning it's result to another variable, you can leave the "call" out. Calls can be used to run a Sub which performs some action. You use "call" when you are telling VB to execute a subroutine or function which does not return an objective result (like a number or a string). So I thought that I would write a do loop in the MS Object to just specifically update things in the worksheet that I am working on, but I get an error:Private Sub Update_Crippling() Dim a 'Initialize Counting Variable a = o Do While i X1 = Cells(5 + i, 15) X2 = Cells(5 + i, 17) Y1 = Cells(5 + i, 16) Y2 = Cells(5 + i, 18) 'Gives out the Width Cells(5 + i, 20) = Call Distance(X1, X2, X3, X4) *****It seems not to like my Call FUNCTION that I use to call the Distance function that I wrote in a module to calcuate the distance between two points***** 'Counting Variable a = a + i LoopEnd SubWhat's wrong with my Call function in the MS Object?Thanks It look likes the functions weren't getting updated when I made a change. And the cells that I use the function in were only updating once in a while, I would get a #Value or #Name error. Thanks for the information wandergeist.I guess my next question is when you are explaining to me the different modulus types in VB:- Microsoft Excel Objects: I take it you meant that these are relevant to only the worksheet- Modulus: Bags of Code that can be called from other Objects Universally- UserForms: What are these? A dialog box to create a button shows up? But you say that these are only meant for that form?- Class Modulus: No UI? What are these?Is there a website out there that explains these types fo things? I have the Power Programming Excel Book for VBA by Walkenbach, but it doesn't explain it very well.Also, being a newbie I programmed everything into the modulus.
