View Full Version : [SOLVED] Command execution VBA

10-13-2014, 04:58 AM

I am using VBA to create an UI for Solver. The problem is that number imputed from textbox appears in excel as a text and solver gives wrong solution.
I tried to solve this by using this command for a few cells that I am changing from UI to format them back to number.

ActiveWorkbook.ActiveSheet.Range("B12").NumberFormat = "0.00"

But i can't get it to execute these commands before running Solver. I put them on a UI button that calls solver but it doesn't work.

Only time it worked was when i put the commands on a button that calls up the UI and didn't run Solver then closed UI and the cells formatted to number witch ruins the whole point of UI if i can format from it and call Solver.

I need to be able to change values in cells then format them to number then call Solver all from UI.

Any other solutions are also acceptable that would put number in cells instead of text from UI.


10-13-2014, 05:34 AM
Maybe something like this...

Dim NumVal As Long
NumVal = textbox1.Value
ActiveWorkbook.ActiveSheet.Range("B12") = NumVal

HTH. Dave

10-13-2014, 06:13 AM
I put this in my textbox and works.

Private Sub TextBox13_Change()

Dim NumVal1 As Long
NumVal1 = TextBox13.Value
ActiveWorkbook.ActiveSheet.Range("E8").Value = NumVal1

End Sub

10-13-2014, 07:24 AM
ActiveWorkbook.ActiveSheet.Range("B12") = CLng(TextBox13)

Use CLng for integer numbers and CDbl for decimal numbers