+ Reply to Thread
Results 1 to 2 of 2

ListBox selection referes to wrong worksheet

  1. #1
    Registered User
    Join Date
    10-09-2017
    Location
    Stavanger, Norway
    MS-Off Ver
    O365
    Posts
    78

    ListBox selection referes to wrong worksheet

    I have a USERForm with a LISTBOX displaying data from a WORKSHEET called "ANALYSISDB", The UserForm is initiated from a WORKSHEET called "PLOT", Through a Macro. On the UserForm there are command buttons to Save, Search, Update and Delete data from the ANALYSISDB sheet. All commands work correctly, APART FROM the delete command. The Data is selected by a Double Click on a row in the ListBox. When The DELETE command is run, a row from the PLOT sheet and not the ANALYSIDB sheet is deleted, it does however selected the correct row number, but from the wrong sheet. How do I ensure the delete command works on the ANALYSISDB sheet, do I need code to force the entire UserForm to refer to the ANALYSISDB sheet, and what is this code. The Code for the Delete command button is below. My VBA skills are limited so any help would be appreciated.

    Private Sub cmd_Delete_Click()

    Dim x As Long
    Dim Y As Long
    x = ThisWorkbook.Worksheets("ANALYSISDB").Range("A" & Rows.Count).End(xlUp).Row
    For Y = 2 To x
    If ThisWorkbook.Worksheets("ANALYSISDB").Cells(Y, 1).Value = txt_Search.Text Then
    Rows(Y).Delete
    End If

    Next Y

    'Clear Data Entry Form
    Me.txt_Search.Value = "-"
    Me.txt_Name.Value = "-"
    Me.cmb_Phase.Value = "0"
    Me.txt_Crest.Value = "0"
    Me.txt_GOC.Value = "0"
    Me.txt_HWC.Value = "0"
    Me.txt_OP.Value = "0"
    Me.txt_GasGrad.Value = "0"
    Me.txt_OilGrad.Value = "0"
    Me.txt_WaterGrad.Value = "0"
    Me.txt_RefWell.Value = "-"
    Me.chbDisplay.Value = False
    Me.chbLabel.Value = False



    MsgBox "Data has been deleted", vbInformation

    txt_Name.SetFocus
    End Sub

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: ListBox selection referes to wrong worksheet

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)

    Administrative Note:

    Welcome to the forum.

    You need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. [SOLVED] transfer listbox selection to different columns of worksheet
    By bqheng in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2018, 07:54 PM
  2. ListBox Selection to apply cost to worksheet
    By Simon1988 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-26-2016, 09:29 AM
  3. [SOLVED] ListBox Double Click () selection from another worksheet and populate data in text box
    By imzhakmaya in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-02-2014, 03:49 AM
  4. Trying to copy a cell range to a different worksheet based on the selection from a ListBox
    By WarrenSmiley in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-10-2013, 03:02 PM
  5. [SOLVED] Delete Worksheet Row By Matching Selection in a Multi Column ListBox
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2013, 11:49 PM
  6. [SOLVED] Copy And Paste Row Into New Worksheet Based On User Listbox Selection
    By Wings249 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2012, 06:58 AM
  7. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM

Tags for this Thread

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