Copy and Delete Row if Validation Equals

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi,

I have a data range on Sheet 1 in Columns A:G and in Column H I have a validation list. What I would like to do is if "Bingo" is selected from the validation list, than i want to copy that row from A:G and paste it in sheet 2 starting in row 5. I can then use .clearcontents and Sort to clean the list up.

Any help is appreciated. Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
try this
Code:
Sub bingo()
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Sheets("Sheet1") 'Edit sheet name
Set sh2 = Sheets("Sheet2") 'Edit sheet name
sh1.Range("H2", sh1.Cells(Rows.Count, 8).End(xlUp)).AutoFilter 1, "Bingo"
sh1.Range("A3", sh1.Cells(Rows.Count, 1).End(xlUp).Offset(, 6)).SpecialCells(xlCellTypeVisible).Copy sh2.Range("A5")
sh1.AutoFilterMode = False
End Sub
 
Last edited:
Upvote 0
The range is static, so I made some changes, but it's not copying correctly. The data starts on row 3 sheet1.

Sub bingo()
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Sheets("Sheet1") 'Edit sheet name
Set sh2 = Sheets("Sheet2") 'Edit sheet name
sh1.Range("H3:H15").AutoFilter 1, "Bingo"
sh1.Range("A3:A15").Offset(, 6)).SpecialCells(xlCellTypeVisible).Copy sh2.Range("A5")
sh1.AutoFilterMode = False
End Sub
 
Upvote 0
This works great, if you are doing a batch at a time. But is there a way to make it live, so that as soon as "Bingo" is selected the row is copied over?

Sub bingo()
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Sheets("sheet1") 'Edit sheet name
Set sh2 = Sheets("sheet2") 'Edit sheet name


sh1.Range("A2:H15").AutoFilter 9, "LOST"
Range("A3:G15").SpecialCells(xlCellTypeVisible).Copy
sh2.Range("A5").PasteSpecial
Range("A3:H15").SpecialCells(xlCellTypeVisible).ClearContents
sh1.AutoFilterMode = False
End Sub
 
Upvote 0
You would have to use event code to do that. Put this in the worksheet code module for the sheet where you have the validation lists.
Code:
Private Sub worksheet_Change(ByVal Target As Range)
If Target.Cells.Count <> 1 Then Exit Sub
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If LCase(Target.Value) = "bingo" Then
            Range("A" & Target.Row).Resize(, 7).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp)(2)
        End If
    End If
End Sub

To access the sheet code module, right click the sheet name tab, then click 'View Code' in the pop up menu. Copy and paste the code into the code module, then save the workbook as a macro enabled workbook to preserve the code. Close the editor and the code will execute when changes occur in column H.. This code assumes that headers will already be on row four of sheet 2.
 
Last edited:
Upvote 0
Thanks!! It wasn't working, so I changed it to call the marco i knew worked. Thanks again for your help!!

Private Sub worksheet_Change(ByVal Target As Range)


If Target.Cells.Count <> 1 Then Exit Sub
If Not Intersect(Target, Range("H3:H15")) Is Nothing Then
Call bingo
End If
End Sub
 
Upvote 0
I just realized that it errors out if something other than "bingo" is put in Column H. How do i change it to only run when "bingo" appears?
 
Upvote 0
This is it, works great. Thanks!!

Private Sub worksheet_Change(ByVal Target As Range)


If Target.Cells.Count <> 1 Then Exit Sub
If Not Intersect(Target, Range("H3:H15")) Is Nothing Then
Select Case Target.Value
Case "bingo"
Call bingo
End Select

End If


End Sub
 
Upvote 0
Glad you got it worked out and thanks for the feedback,
regards, JLG
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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