Deleting Entire Row if a Cell Located in Column A contains "1"

eagerbeav3r

New Member
Joined
Feb 24, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hey everyone,

I searched for a solution on this but I didnt find anything that works for me.
The Commandbutton for this is located in Sheet 1 and i want the VBA Code to delete every row that contains "1" in Sheet 3,

VBA Code:
If ActiveSheet.CheckBox1 = False Then

'This is where I need the Code to work
 
How about:

VBA Code:
Sub Test1()
'
    Dim ArrayRow        As Long, LastRow    As Long
    Dim rng             As Range
    Dim SearchString    As String
    Dim InputArray      As Variant
    Dim ws              As Worksheet
'
    SearchString = "1"                                                                  ' <--- Set this to the string to search for
    Set ws = Sheets("Sheet3")                                                           ' <--- Set this to the sheet name to be checked
'
    LastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
'
    Set rng = ws.Range("A" & LastRow + 1)
'
    InputArray = ws.Range("A1:A" & LastRow).Value
'
    For ArrayRow = 1 To UBound(InputArray)
        If InputArray(ArrayRow, 1) = SearchString Then Set rng = Union(rng, ws.Range("A" & ArrayRow))
    Next
'
    rng.EntireRow.Delete
End Sub

This works best for me. Thanks for the many suggestions :)
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Glad you got something that suits. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

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