1

I am trying to create a function that will take the value of a cell formatted something like 5.23*10^-3 and be able to use it in a calculation.

Sub Multiplication_Stuff
Dim a As Double

a = Range('ActiveSheet!$B$2').Value   *****
c = multiplyme(a)

Range("Sheet1!B7) = C
End Sub

Public Function multiplyme(a As Double) As Double
multiplyme = a * 15
End Function

I received the following error in the code:

run-time error'1004' Method 'Range'Of object'_Global' failed

I have also had it formatted the way the range for c is formatted and recieved the same error. i would prefer it to not pull from active sheet but sheet 1 instead.

1 Answer 1

1

In VBA, a Sheet and a Cell are two DIFFERENT objects:

Sub Multiplication_Stuff
    Dim a As Double, c As Double

    a = ActiveSheet.Range("B2").Value
    c = multiplyme(a)

    Sheets("Sheet1").Range("B7").Value = c
End Sub

Public Function multiplyme(a As Double) As Double
    multiplyme = a * 15
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.