Results 1 to 5 of 5

Thread: VBA code to clear range and text box
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jan 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA code to clear range and text box

    I have the below code which clears specific cells after a worksheet is emailed. I need to add TextBox1, TextBox2 and TextBox3 to the code to clear contents also. any help adding this into the below VBA code?





    MsgBox "Your email was sent." & vbNewLine & "The form will now be reset.", vbInformation, "Success!"

    Application.ScreenUpdating = False

    Range("g10:j24,h27,h28,h30,h31,W28:W32,").Select
    Selection.ClearContents
    Range("d3").Select

    Application.ScreenUpdating = True


    End Sub

  2. #2
    Board Regular sykes's Avatar
    Join Date
    May 2002
    Location
    Cornwall,England
    Posts
    1,560
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA code to clear range and text box

    Where are these textboxes? on a worksheet (if so, what's the name of the sheet) or on a userform?
    Sykes
    Windows 10 / XL 2016
    Members don't have crystal balls, so PLEASE describe your situation, code,
    and requirements ACCURATELY in your first post. It saves hair!
    Better still - upload your spreadsheet (and formulae!) with this great bit of kit.


    - forum use guidelines, forum rules and terms of use
    - Try searching for your answer first, see how
    - Read the FAQs
    - List of BB codes

  3. #3
    New Member
    Join Date
    Jan 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA code to clear range and text box

    Hi

    yes on a worksheet named Dashboard.

    VBA assigned to a button that emails worksheet named dashboard and clears the sheet of inputted data.
    the text boxes are "Text boxes (Activex)"

  4. #4
    Board Regular sykes's Avatar
    Join Date
    May 2002
    Location
    Cornwall,England
    Posts
    1,560
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA code to clear range and text box

    This should work.
    You've either not given the procedure a name, or only copied part of it into your post, so I've left the top part exactly as-is.
    Code:
    MsgBox "Your email was sent." & vbNewLine & "The form will now be reset.", vbInformation, "Success!"
    
    Application.ScreenUpdating = False
    
    Range("g10:j24,h27,h28,h30,h31,W28:W32,").Select
    Selection.ClearContents
    
        With Sheets("Dashboard")
            .TextBox1.Value = ""
            .TextBox2.Value = ""
            .TextBox3.Value = ""
        End With
    
    
    Range("d3").Select
    
    Application.ScreenUpdating = True
    
    
    End Sub
    As you've not said where this code resides, I've also had to assume it's in a code module.
    Last edited by sykes; Jul 17th, 2019 at 07:48 AM.
    Sykes
    Windows 10 / XL 2016
    Members don't have crystal balls, so PLEASE describe your situation, code,
    and requirements ACCURATELY in your first post. It saves hair!
    Better still - upload your spreadsheet (and formulae!) with this great bit of kit.


    - forum use guidelines, forum rules and terms of use
    - Try searching for your answer first, see how
    - Read the FAQs
    - List of BB codes

  5. #5
    Board Regular sykes's Avatar
    Join Date
    May 2002
    Location
    Cornwall,England
    Posts
    1,560
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA code to clear range and text box

    @kroters Did this do the trick?
    Sykes
    Windows 10 / XL 2016
    Members don't have crystal balls, so PLEASE describe your situation, code,
    and requirements ACCURATELY in your first post. It saves hair!
    Better still - upload your spreadsheet (and formulae!) with this great bit of kit.


    - forum use guidelines, forum rules and terms of use
    - Try searching for your answer first, see how
    - Read the FAQs
    - List of BB codes

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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