deleting macro issue

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have this macro here that I use to delete from my worksheet. I just found out that when I delete, the numbering I used is not updated. So I have commented that out in the code below:
Code:
 findvalue.Value = ""
now what I wanna do is after deleting and sorting the data excluding the column B, I want to go down column B to the last cell with data and delete that number. I need your help with this one. I see it as a challenge but I know you see it as a hobby. Thanks
Kelly
Code:
Private Sub CmdDelete_Click()
    Dim sht As String, findvalue, answer
    sht = ComboBox1.Value
    On Error GoTo errHandler
    If Rw2.Value = "" Or Rw3.Value = "" Then
        MsgBox "There is no data to delete. Select data first"
        Exit Sub
    End If
    answer = MsgBox("Are you sure you want to delete the name: " & Rw2.Value & "?", vbYesNo + vbQuestion, _
    "Delete this name")
    If answer = vbYes Then
    Set findvalue = Sheets(sht).Range("B7:B10000").Find(What:=Me.Rw1, LookIn:=xlValues)
        ‘findvalue.Value = ""
            findvalue.Offset(0, 1).Value = ""
                findvalue.Offset(0, 2).Value = ""
                    findvalue.Offset(0, 3).Value = ""
                        findvalue.Offset(0, 4).Value = ""
                            findvalue.Offset(0, 5).Value = ""
                                findvalue.Offset(0, 6).Value = ""
                            findvalue.Offset(0, 7).Value = ""
                        findvalue.Offset(0, 8).Value = ""
                    findvalue.Offset(0, 9).Value = ""
                findvalue.Offset(0, 10).Value = ""
            findvalue.Offset(0, 11).Value = ""
                Else
            MsgBox "Deletion cancelled", vbInformation, "Deletion Alert"
            Exit Sub
        End If
        
        SortIt

            MsgBox "Deletion successful", vbInformation, "Deletion Alert"
    On Error GoTo 0
    Exit Sub
errHandler::
    MsgBox "An error has occured"
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I think you should explain in words what your wanting and not expect us to understand your script.

I do not think any script needs to be written like this.
 
Upvote 0
Okay, i use the code to delete by filling the cells with blanks but leaves column B. Then after that i sort. So after the sort, there will be an extra data in column B. So i want to get that data deleted so that i can have it match the other columns.
That is say i have 10 rows of data, when i delete, the other columns will have 9 rows with data while the column B will still have the 11 since i did not delete entire row. So that last row in column B, i want it content cleared.
Hope this helps
Kelly
 
Upvote 0
Okay, i use the code to delete by filling the cells with blanks but leaves column B. Then after that i sort. So after the sort, there will be an extra data in column B. So i want to get that data deleted so that i can have it match the other columns.
That is say i have 10 rows of data, when i delete, the other columns will have 9 rows with data while the column B will still have the 11 since i did not delete entire row. So that last row in column B, i want it content cleared.
Hope this helps
Kelly

I made a typo error here; just corrected it.
That is say i have 10 rows of data, when i delete, the other columns will have 9 rows with data while the column B will still have the 10 since i did not delete entire row. So that last row in column B, i want it content cleared.
 
Last edited:
Upvote 0
Code:
Private Sub CmdDelete_Click()
Dim sht As String, findvalue
sht = ComboBox1.Value
If Rw2.Value = "" Or Rw3.Value = "" Then
    MsgBox "There is no data to delete. Select data first"
    Exit Sub
End If
If MsgBox("Are you sure you want to delete the name: " & Rw2.Value & "?", vbYesNo + vbQuestion, _
    "Delete this name") = vbNo Then Exit Sub
Set findvalue = Sheets(sht).Range("B7:B10000").Find(What:=Me.Rw1, LookIn:=xlValues)
If findvalue Is Nothing Then
    MsgBox "Value not found."
    Exit Sub
Else
    findvalue.Offset(0, 1).Resize(, 11).ClearContents
End If
SortIt
[COLOR=#ff0000]Cells(Rows.Count, "B").End(xlUp).ClearContents[/COLOR]
MsgBox "Deletion successful", vbInformation, "Deletion Alert"
Exit Sub
 
Upvote 0
Very accurate!!!! Thanks a lot. I am very grateful.
 
Last edited:
Upvote 0
Or perhaps this does what you need :
Code:
Private Sub CmdDelete_Click()
Dim sht As String, findvalue
sht = ComboBox1.Value
If Rw2.Value = "" Or Rw3.Value = "" Then
    MsgBox "There is no data to delete. Select data first"
    Exit Sub
End If
If MsgBox("Are you sure you want to delete the name: " & Rw2.Value & "?", vbYesNo + vbQuestion, _
    "Delete this name") = vbNo Then Exit Sub
Set findvalue = Sheets(sht).Range("B7:B10000").Find(What:=Me.Rw1, LookIn:=xlValues)
If findvalue Is Nothing Then
    MsgBox "Value not found."
    Exit Sub
Else
    [COLOR=#ff0000]findvalue.Resize(, 12)[/COLOR].ClearContents
End If
SortIt
sgBox "Deletion successful", vbInformation, "Deletion Alert"
Exit Sub
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,795
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top