Consulting

Results 1 to 4 of 4

Thread: Command execution VBA

  1. #1

    Command execution VBA

    Hi,

    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.

    Thanks

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Maybe something like this...
    Dim NumVal As Long
    NumVal = textbox1.Value
    ActiveWorkbook.ActiveSheet.Range("B12") = NumVal
    HTH. Dave

  3. #3
    Thx
    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

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ActiveWorkbook.ActiveSheet.Range("B12") = CLng(TextBox13)
    Use CLng for integer numbers and CDbl for decimal numbers
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •