Sum with variable in VBA macro

DEN91 -  
 Loumie64 -
Hello,

I have a small issue with performing a simple addition of a certain number of cells in the same column using a variable.

The number of cells may vary with each execution of the macro.

For example:

I want to sum from cell D2 to cell Dx (where x is my variable) and have the total in cell Dx +1.

At the beginning of my macro, I initialize the variable but after that, I can't seem to reuse that same variable in the sum function that I want to perform.

Thank you for your help...
Configuration: Windows XP Internet Explorer 6.0

10 answers

melanie1324
 
Hello,

sub sum
dim sum,line as string
sum = 0
line = 2
do while cells(line, 5) <> ""
sum = sum + cells(line, 5)
line = line + 1
loop

cells(line, 5) = 5

end sub

See you later
0