How to use variable in code

B

BRC

sub filldata

dim cap as long
' for purpose this of illustration F16= .15
cap = Sheet4.Range("f16").Value
' to verify that cap is initialized
Msgbox(cap)
' for purpose of illustration c6=.20
Range("d6").Formula = "=IF(c6<0,0,IF(c6>cap,cap,c6))"
end sub

If I replace "cap" with a number ( .15) it works fine but when I try to
use the variable cap I get a #name? error in the cells.
I believe I may not using correct punctuation around the variable. Any
suggestions Thanks
BRC
 
G

Gary Keramidas

you can try this

Range("d6").Formula = "=IF(c6<0,0,IF(c6>" & cap & "," & cap & ",c6))"
 
B

BRC

Sorry about that, I had removed the "long" from the dim statement. I
just had "dim cap " which I believe initializes a varient. Should I be
using something else there? Thanks
 
B

Bob Phillips

Yeah, if it will only be a number

Dim cap As Double

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top