WWXX
05-20-2009, 07:00 AM
Hi, I just start to learn about the powerful VBA, and when I start writing my own spreadsheet, I ran into one problem which need the help from you guys. (See my attached Excel)
I have write a function call "readinput" and another function call "aa"
Function readinput(req)
Application.Volatile
a = Range("B3")
b = Range("B4")
c = Range("B5")
Select Case req
Case 1
readinput = a
Case 2
readinput = b
Case 3
readinput = c
End Select
End Function
Function aa(req)
'Application.Volatile
Select Case req
Case 1
aa = readinput(1) + readinput(2) + readinput(3)
Case 2
aa = readinput(1) * readinput(2) * readinput(3)
End Select
End Function
When (at cell B8) aa(1) it give the sum of cell B3 + B4 + B5,
and (at cell C8) aa(2) is equal to cell B3 x B4 x B5
It works perfectly in one sheet, but when I update the answer in sheet1, and goes to sheet2, the sheet2 answer is same as sheet1....
Everytime i will need to click on a cell in sheet2 to make the answer fits sheet 2, but goes back to sheet1, the answer in sheet1 shows sheet2 answer....
The problem is the "readinput" function, as it always refer to the "Sheet" that was modify perviously.
How can I improve the "readinput" function so that I can get rid of this silly problem...??
I have write a function call "readinput" and another function call "aa"
Function readinput(req)
Application.Volatile
a = Range("B3")
b = Range("B4")
c = Range("B5")
Select Case req
Case 1
readinput = a
Case 2
readinput = b
Case 3
readinput = c
End Select
End Function
Function aa(req)
'Application.Volatile
Select Case req
Case 1
aa = readinput(1) + readinput(2) + readinput(3)
Case 2
aa = readinput(1) * readinput(2) * readinput(3)
End Select
End Function
When (at cell B8) aa(1) it give the sum of cell B3 + B4 + B5,
and (at cell C8) aa(2) is equal to cell B3 x B4 x B5
It works perfectly in one sheet, but when I update the answer in sheet1, and goes to sheet2, the sheet2 answer is same as sheet1....
Everytime i will need to click on a cell in sheet2 to make the answer fits sheet 2, but goes back to sheet1, the answer in sheet1 shows sheet2 answer....
The problem is the "readinput" function, as it always refer to the "Sheet" that was modify perviously.
How can I improve the "readinput" function so that I can get rid of this silly problem...??