0

I have this code where ttlMtrs is an integer < 7000

diffFormula = "=1-(" & ttlMtrs & "/7000)*1200"
Debug.Print diffForumla

I am trying to build a string that will evaluate once printed to a cell in excel. When I Debug.print to check the string I only get blank lines. One time I got long string of garbage characters.

I am trying to figure out what I am misunderstanding in building this string. Any ideas are appreciated.

2
  • 2
    looks to me like 1 left bracket and two right ones. Commented Jun 28, 2018 at 13:25
  • 4
    I honestly couldn't tell you how many times I've recommended Option Explicit this week. Commented Jun 28, 2018 at 13:30

2 Answers 2

2

you have mispelled the variable name in the debug statement

Debug.Print diffForumla

should be

Debug.Print diffFormula

note the changed position of the u

Sign up to request clarification or add additional context in comments.

2 Comments

Using Option Explicit in your module will help you avoid this kind of error.
Thank you, I feel pretty silly. Before it was printing some garbage errors but this is the answer. Thank you.
1
Public Sub Test()

    Dim ttlMtrs As String
    Dim diffFormula As String
    diffFormula = "=1-(" & ttlMtrs & "/7000)*1200)"
    Debug.Print diffFormula

End Sub

This should be the result:

=1-(/7000)*1200)

1 Comment

uneven bracketing.

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.