+ Reply to Thread
Results 1 to 2 of 2

I have an error in my code again and can't work it out again.

  1. #1
    Registered User
    Join Date
    12-09-2020
    Location
    australia
    MS-Off Ver
    2010
    Posts
    12

    Exclamation I have an error in my code again and can't work it out again.

    I am trying to delete a row based on listbox selection but keep returning an error.

    Below is the code I am using any help would be great.

    Thank you.

    Private Sub cmdRemove_Click()

    Dim iRow As Long

    If lstBudget = 0 Then

    MsgBox "No row is selected.", vbOKOnly + vbInformation, "Delete"
    Exit Sub
    End If

    Dim i As VbMsgBoxResult

    i = MsgBox("Do you want to delete the selected record?", vbYesNo + vbQuestion, "Confirmation")

    If i = vbNo Then Exit Sub

    iRow = Application.WorksheetFunction.Match(Me.lstBudget.List.List(Me.lstBudget.List.ListIndex, 0), _
    ThisWorkbook.Sheets("Output").Range("A:A"), 0)

    ThisWorkbook.Sheets("output").Rows(iRow).Delete

    Call Reset

    MsgBox "Selected record has been deleted.", vbOKOnly + vbInformation, "Deleted"

    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: I have an error in my code again and can't work it out again.

    there is a direct link between the listbox index and the row on the sheet - there is no need to do a search routine.
    also put option explicit as your very first line and declare your variables at the head - do not litter them randomly through the different subs - there is only need then to declare them once.
    Also please put your submitted codes between code tags before the moderators smack your knuckles for not reading the forum rules

    Please Login or Register  to view this content.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

+ 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] Need help, Code use to work but now it does not, No error just no data transfered
    By jrtraylor in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-11-2017, 11:31 AM
  2. [SOLVED] Code was working perfectly, but now will not work after an error window popped up...
    By ekf23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2014, 09:45 AM
  3. [SOLVED] Excel VBA Code + Error when trying to run multiple scripts in one work sheet.
    By blckhandsid3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2013, 05:27 PM
  4. [SOLVED] Why the Same Code VBA can not work and error after modified table
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-09-2013, 05:52 AM
  5. Getting this code to work on MAC (ERROR 68) - works fine on Windows
    By LT1511 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2012, 11:09 PM
  6. coding error when trying to chanage code to work on same sheet but different area
    By jabjab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2011, 12:45 PM
  7. Code Error - Still at work and need help!
    By alexm999 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2006, 11:10 PM

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