Results 1 to 15 of 15

Deleting a record in a table, using VBA

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-10-2013
    Location
    Wolverhampton
    MS-Off Ver
    Excel 2010
    Posts
    101

    Deleting a record in a table, using VBA

    Hi, I have the following code (see below) which is supposed to select a record in a table when the user enters a customer ID in the textbox of a userform, and then clicks OK, for some reason however, it is not working, when I enter a customer ID in the textbox, and then when I click on OK, all that pop ups is the error message stating that the customer ID could not be found, even when the ID is in actual fact located in the table.

    My table starts in cell 7, (cell 6 if including headings) and there are 5099 records and there are 23 fields, so the table ends in column V.

    Could someone please help me

    Private Sub CommandButton2_Click()
    
    Dim i As Long, lrow As Long, rcount As Long
    
    With Worksheets("Sheet1")
        lrow = .Range("B" & .Rows.Count).End(xlUp).Row
        For i = 4 To lrow
            If .Range("B" & i).Value = TextBox1.Value Then
                .Rows(i).Select
                rcount = rcount + 1
            End If
        Next i
        If rcount = 0 Then MsgBox "ID not found"
    End With
    End Sub
    Last edited by nav505; 03-13-2013 at 01:13 PM.

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