# Thread: FUNCTION AND USE ..... (2000 sr-1)

1. ## FUNCTION AND USE ..... (2000 sr-1)

Assuming i have this heet (range P2:AI...)

i want with a function to calculate the algebric summ in column AJ...

you know:

in all cell of this range use the sign - for all number present in column P, and the sign + for all number present in colum Q the...
in all cell of this range use the sign - for all number present in column R, and the sign + for all number present in colum S the...
in all cell of this range use the sign - for all number present in column T, and the sign + for all number present in colum U the...

ecc...

now how to use you function to have the result in .range("AJ"+count)=your_function...

2. ## Re: FUNCTION AND USE ..... (2000 sr-1)

Sub blahblah()
Dim lngRow As Long
Dim lngMaxRow As Long
Dim dblSum As Double
Dim lngCol As Long
lngMaxRow = Cells(Rows.Count, "P").End(xlUp).Row
For lngRow = 2 To lngMaxRow
dblSum = 0
For lngCol = 16 To 35 ' P to AI
If lngCol Mod 2 = 0 Then
dblSum = dblSum + Cells(lngRow, lngCol)
Else
dblSum = dblSum - Cells(lngRow, lngCol)
End If
Next lngCol
Cells(lngRow, "AJ") = dblSum
Next lngRow
End Sub

3. ## Re: FUNCTION AND USE ..... (2000 sr-1)

big!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

but you know i use alwys the a range similar range("AJ"+RIGA)=ecc....(RGA is my ######er)
is possible transform this macro in function and use in this range? if yes ihow to use in range?
Tks

4. ## Re: FUNCTION AND USE ..... (2000 sr-1)

When I give you a function, you want a procedure, and when I give you a procedure, you want a function... <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Here is the function:

Function AlternatingSum(lngRow As Long) As Double
Dim lngCol As Long
For lngCol = 16 To 35 ' P to AI
If lngCol Mod 2 = 0 Then
AlternatingSum = AlternatingSum + Cells(lngRow, lngCol)
Else
AlternatingSum = AlternatingSum - Cells(lngRow, lngCol)
End If
Next lngCol
End Function

Use it like this:

Range("AJ" & RIGA) = AlternatingSum(RIGA)

5. ## Re: FUNCTION AND USE ..... (2000 sr-1)

yes you are right...
But after 3 year on this forum now i have understand the 70% the use of a function:-)

Remenber:

Sal=active.cell(0,0)
Hans=active.cell(100000,1000000)

is this my first consideration on you in 2003:-)

6. ## Re: FUNCTION AND USE ..... (2000 sr-1)

hummm
but why you use alway ...& RIGA insted ...+RIGA not is the same result?
To understand, tell me.
Tks.

7. ## Re: FUNCTION AND USE ..... (2000 sr-1)

You can use both + RIGA and & RIGA. I prefer to use & because that is the 'concatenation' operator for strings, while + is mostly used to add numbers. In some situations, + might not return the expected result.

8. ## Re: FUNCTION AND USE ..... (2000 sr-1)

In your "Honor" i use & RIGA....

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•