Running For loop to Delete the same row 'x' number of times.

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I am trying to get my code to check the number of lines through a cell value, and then repeatedly delete the row 'x' number of times.

My problem is that I use a unique identifier to find the row to start the deletion process, but once that row is deleted first the code is unable to locate what to delete anymore. How can I lock in the row once I have found it so that the code can delete 'x' number of times?

My code (cNum is set to the value of 1)
VBA Code:
        Set findvalue = DataSH.Range("A:A").Find(What:=Me.IDnumber.Value, _
        LookIn:=xlValues, LookAt:=xlWhole)
        
        x = findvalue.Offset(0, 12).Value
        'delete the entire row
        For cNum = 1 To x
            findvalue.EntireRow.Delete ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        Next cNum

Once findvalue is set I think I need to change it to the row number permanently for the remainder of the for loop, but I am not sure how to accomplish this or if it would work that way.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Instead of a loop try resizing the range:
findvalue.resize(x).EntireRow.Delete
 
Upvote 0
Solution

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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