+ Reply to Thread
Results 1 to 4 of 4

Userform Error with Blank RefEdit.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2010
    Location
    Hereford, England
    MS-Off Ver
    Excel 2003
    Posts
    73

    Userform Error with Blank RefEdit.

    Hi all,

    I've got a userform that the user will enter a row into the RefEdit box and click a command button to perform an action. However if someone enters nothing into the RefEdit box and clicks the command button I get an error midway through the macro so that I have to reset.
    There's undoubtedly a way to tell it that upon blank click do nothing, but I haven't learnt how to ask it.
    Can anyone help?

    p.s. Attached is an example of my problem. I'm beginning to think that I might just become a fruit & veg trader as I keep using them for examples lol.
    Attached Files Attached Files
    Last edited by Baziwan; 07-04-2010 at 04:25 PM.
    Kind Regards

    Baz

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

    Re: Userform Error with Blank RefEdit.

    Possibly an error statement would work
    Private Sub CommandButton1_Click()
        On Error Resume Next
        Range(RefEdit1).Copy
        Range(RefEdit1).Insert Shift:=xlDown
        Range(RefEdit1).Offset(-1, 0).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
                                                   SkipBlanks:=False, Transpose:=False
        Unload Me
        UserForm3.Show
    End Sub

  3. #3
    Registered User
    Join Date
    06-12-2010
    Location
    Hereford, England
    MS-Off Ver
    Excel 2003
    Posts
    73

    Re: Userform Error with Blank RefEdit.

    Quote Originally Posted by davesexcel View Post
    Possibly an error statement would work
    Thanks alot Dave, yeah the on error solves it.

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

    Re: Userform Error with Blank RefEdit.

    Try this as an alternative
    
    Private Sub CommandButton1_Click()
        Dim rRng As Range
        Set rRng = Range(RefEdit1)
        If rRng Is Nothing Then GoTo exit_proc
        With rRng
            .Copy
            .Insert Shift:=xlDown
            .Offset(-1, 0).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
                                        SkipBlanks:=False, Transpose:=False
    exit_proc:
        End With
        Unload Me
        UserForm3.Show
    End Sub
    Hope that helps.

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

    Free DataBaseForm example

+ 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