+ Reply to Thread
Results 1 to 3 of 3

Delete Row from User Form in Excel

  1. #1
    Registered User
    Join Date
    12-15-2007
    Location
    India
    Posts
    9

    Delete Row from User Form in Excel

    Hi,

    Myself Harindra, i have a problem while deleting the row in excel sheet from User Form.

    1) I created a user form and in that i given a search function & delete function, when i search a data using search text box, it displayed in List Box1, but a problem arise when i try to delete the entire row it not getting deleted.

    Please Help me in this.

    Waiting for reply,

    Harindra Devadiga
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-25-2006
    Posts
    54
    Hi Harindra

    If you put a msggbox after C=activecell in your delete button command you'll see it returns " " (nothing)

    The problem is this line in your search button code;
    Set r = .Range("DataRange").Find(What:=res, LookAt:=xlWhole, LookIn:=xlValues, MatchCase:=False)
    Although the code is correctly finding the text it's not actually activating the cell.

    In your search button on_click event I added these two lines (the top one is yours)
    If Not r Is Nothing Then
    founditem = r.Address
    Range(founditem).Activate
    This then activates the cell found in your search button routine and then the DELETE button routine works ok as it has an activecell to work with.

    BE AWARE that if you have multiple search results in your list box then this will only return the LAST item found as your activecell so, if this is likely to happen, it may be worth re-finding the item selected form the list box as part of the DELETE button routine.

    Hope all this makes sense!

    A

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    As Andy says your code won't delete the row because it is not active. However, it is not necessary to activate the cell. Change your code to be more efficient by
    1. Do not use R to refer to the found cell, because you use R in the code I provided yesterday as a Long.
    2.Place at the very top of your code (where you should actually have Option Explicit)
    Please Login or Register  to view this content.
    Then use rCl where you use r as range.
    Please Login or Register  to view this content.
    You really should also read the topic I suggested yesterday & also take a look at the DatabaseForm example there.
    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