+ Reply to Thread
Results 1 to 3 of 3

Userform textbox dous not write to the worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    2

    Userform textbox dous not write to the worksheet

    I think this is a simple question but because i'm new to VBA coding its a mindbreaker for me...

    I'm building a simple userform so the user can put in the values in a form instead of the Excel worksheet. In this userform there are nummers like 1,20 (comma separated numbers) when these numbers are placed on the worksheet there is no calculation made when I enter an number without a comma the calculation is being made (at the worksheet i want to keep the calculations, I do not want to transfer the calculations to the VBA, this is more convienient for me)

    When I enter the "fresh value" direct is the worksheet cel the calculation is made... What am I doing wrong???

    I've seen that I have to calculate or activate the sheet so I can Write DIRECT into the sheet, Please help. ;-)


    Here the code I'm using...

    -----------------------------------------------------------------------------------------
    Option Explicit
    
    Private Sub UserForm_Initialize()
    Dim hWnd As Long, lStyle As Long
    If Val(Application.Version) >= 9 Then
    hWnd = FindWindow("ThunderDFrame", Me.Caption)
    Else
    hWnd = FindWindow("ThunderXFrame", Me.Caption)
    End If
    lStyle = GetWindowLong(hWnd, GWL_STYLE)
    SetWindowLong hWnd, GWL_STYLE, (lStyle And Not WS_SYSMENU)
    End Sub
    
    Private Sub CmdClose_Click()
    Unload Me
    
    End Sub
    
    Private Sub CommandButton1_Click()
    
    Dim ws As Worksheet
    Set ws = Worksheets("Quality Evidence Testvorm")
        Worksheets("Quality Evidence Testvorm").Range("K10").Value = Me.TextBox1.Value
        Worksheets("Quality Evidence Testvorm").Range("K11").Value = Me.TextBox2.Value
        Worksheets("Quality Evidence Testvorm").Range("K13").Value = Me.TextBox3.Value
        MsgBox "De informatie is voor het QE protocol opgeslagen"
    
    
    End Sub
    
    
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    
    If Not MsgBox("Wil je dit venster werkelijk sluiten?", vbYesNo, "Terminate Execution") = vbYes Then
        Cancel = True
    End If
    
    End Sub
    Last edited by Mieska; 02-10-2012 at 07:31 PM. Reason: Added Code Tags

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform textbox dous not write to the worksheet

    There' no point declaring a variable ws, giving it a value then not using it. In this example it's not really necessary

    You don't need to activate the worksheet.

    The values in the TextBoxes are by default Strings, so cannot be used in calculations. You ned to convert them to a numeric value by using CDbl for a decimal value or Clng., or simply use Val

    Private Sub CommandButton1_Click()
    
    With Worksheets("Quality Evidence Testvorm")
       .Range("K10").Value = Val(Me.TextBox1.Value)
       .Range("K11").Value = Val(Me.TextBox2.Value)
       .Range("K13").Value = Val(Me.TextBox3.Value)
        MsgBox "De informatie is voor het QE protocol opgeslagen"
    End With
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    02-04-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Userform textbox dous not write to the worksheet

    Thanks mate, this solved the problem.. As I said I'm new...
    The only thing is that my value has to be as 0.20 instead of the usual 0,20 (wich is my normal input value) If I use the Comma than the value is set to a roud figure...
    I want to learn about codes, can someone call out some sites where I can see different codes and sites where coding is explained.

    Thanks in advance for all the answers.

    Newbie Mieska

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1