PinkeyNBrain
IS-IT--Management
Basics of problem:
- Read value from cell into a var:
EX: myvar = .Range("B300").Value ' say val is 0.023
- Copy val into another cell:
EX: .Range("B3").Value = myvar ' B3 now contains 0.0230000000447035
More;
- Excel 2010
- B300 format = General
- myvar is DIMed as Variant
- B3 format = Number
Tried:
- .Range("B3").Value = CDec(myvar) ' And CSng()
- .Range("B3").Formula = CDec / CSng
- .Range("B3").Value = myvar + 0.0 ' Not really 0.0 keeps changing to 0# ???
I'm guessing that it's fallout of VBA trying to convert between different vartypes, but I'm at a loss as to what to do about it.
- Read value from cell into a var:
EX: myvar = .Range("B300").Value ' say val is 0.023
- Copy val into another cell:
EX: .Range("B3").Value = myvar ' B3 now contains 0.0230000000447035
More;
- Excel 2010
- B300 format = General
- myvar is DIMed as Variant
- B3 format = Number
Tried:
- .Range("B3").Value = CDec(myvar) ' And CSng()
- .Range("B3").Formula = CDec / CSng
- .Range("B3").Value = myvar + 0.0 ' Not really 0.0 keeps changing to 0# ???
I'm guessing that it's fallout of VBA trying to convert between different vartypes, but I'm at a loss as to what to do about it.