Find and delete row

jimmisavage

Board Regular
Joined
Jun 28, 2017
Messages
130
Hi,
I'm trying to find a row based on a combobox1. It's working on one sheet, but not on another - on the other sheet it seems to delete the column below the one i'm expecting. Can anyone shed some light on why this might happen?

Code:
Private Sub CommandButton2_Click()    Sheets("Study Database").Select
    Columns("B:B").Select
        Cells.Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Select
        Rows(ActiveCell.Row).EntireRow.Delete
    Range("A1").Select
    'next
    Sheets("Study Snapshot").Select
    Columns("E:E").Select
        Cells.Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Select
        Rows(ActiveCell.Row).EntireRow.Delete
    Range("A1").Select
    Sheets("Admin").Select
    Unload Me
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Do you have any merged cells on that sheet?
 
Upvote 0
Actually, yes I do. Cells in row b and c are merged together. Is this what's throwing it off?

How would I counter this?
 
Upvote 0
Actually, yes I do. Cells in row b and c are merged together. Is this what's throwing it off?
Yup


How would I counter this?
Get rid of the merged cells. They are about the worst thing you can do to a spreadsheet and should be avoided like the plague.
 
Upvote 0
Actually Fluff,
Sorry to be a pain but it's just happened again. There are no merged cells now.

In fact, if I put an error in before the part where it deletes I can see the combobox1 has actually changed to the next selection in the dropdown list. This is why it's deleting the line below the one i actually want.
Do you have any idea why this would happen?
 
Upvote 0
How is the combo being populated?
 
Upvote 0
I've 'fixed' it by choosing to delete the row above the active cell but it's not an ideal solution. If anyone else has an idea i would really appreciate it.

Code:
Sheets("Study Snapshot").Select    Columns("E:E").Select
        Cells.Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Select
        Rows(ActiveCell.Row - 1).EntireRow.Delete
    Range("A1").Select
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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