+ Reply to Thread
Results 1 to 7 of 7

Using userform textbox value in code result

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Using userform textbox value in code result

    I'm hitting problem after problem today.

    I have a user form, it has a combo box with letters sent to customers, next to it I have a text box where the date of the letter is added. When the command button is selected a set script will be produced and it will mention the letter was sent on X date. X needs to be the value in the textbox from

    When I was referencing cell values in excel it was easy as I would use " & Sheets("Sheet1".range("A1") & " but I'm rebuilding using a userform rather than drop down boxes and cells in excel and I can't quite work it out.

    How do I do something similiar using the textbox value, I have tried the same " & ... & " using the textbox name and value (UoWD.Value) but it's not working. I've googled but can't quite find what I need.

    Any ideas clever people than I?

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Using userform textbox value in code result

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Using userform textbox value in code result

    Not sure what UoWD is? You need to refer to the textbox value like so:

    UserForm1.TextBox1.Value
    Maybe attach your workbook with the form in it, if you're still struggling.

    It might also be a nice idea to add a calendar control to select a date, rather than a text box
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: Using userform textbox value in code result

    I can't the file is too large

    ' Sophisticated Letter & UoW Closure

       ElseIf MTT_Script.UoW = "Sophistication: Awaiting Uow Closure" And MTT_Script.Letter = "Sophisticated" Then
            Sheets("Sheet2").Select
            Range("D2:S32").Select
            Selection.ClearContents
            Selection.Font.Underline = xlUnderlineStyleNone
            Selection.Font.ColorIndex = 0
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .MergeCells = True
            .WrapText = True
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        With Sheets("Sheet2").Range("D2:S32")
        End With
            .Value = "“Your case has been deemed Sophisticated which means you are not in scope of the review.“" & vbNewLine & _
            vbNewLine & _
            "“We wrote to you on " & Sheets("Sheet1").Range("P20") & " to advise you of this and to ask whether you wanted to provide further information“" & vbNewLine & _
            vbNewLine & _
            "“Have you received this letter?“" & vbNewLine & _
            "If No - Select the Unreceived Letters Button."
            .Font.Name = "Arial"
            .Font.Size = 22
            Range("A1").Select
        End With
    Should clarify, Userform is called "MTT_Script" combobox is "called UoW" and texbox is called (UoWD).

    I'd like to replace the below in the end script

    " & Sheets("Sheet1").Range("P20") & "
    with OllyXLS suggestion of

    UserForm1.TextBox1.Value
    Last edited by Sc0tt1e; 11-29-2013 at 10:14 AM.

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Using userform textbox value in code result

    Sorry, what has that code got to do with referencing the value of a userform textbox?

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using userform textbox value in code result

    Change Sheets("Sheet1").Range("P20") to MTT_Script.UoWD.Text

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Using userform textbox value in code result

    Quote Originally Posted by OllyXLS View Post
    Sorry, what has that code got to do with referencing the value of a userform textbox?
    I love it when people edit posts AFTER I've questioned them... Makes my posts look real smart!

    Quote Originally Posted by Izandol View Post
    Change Sheets("Sheet1").Range("P20") to MTT_Script.UoWD.Text

    Yes, that should do it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Userform TextBox.Value inside Formula, in VBA code
    By schneij in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2013, 06:03 PM
  2. Display result in userform (vba) textbox
    By ilovelagar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2009, 04:47 PM
  3. Userform textbox code
    By CJ-22 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-30-2008, 10:27 AM
  4. [SOLVED] formulae:Help with UserForm textbox code
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2006, 06:25 PM
  5. [SOLVED] Help with UserForm textbox code
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2006, 05:40 PM

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