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

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
135
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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,468
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Instead of a loop try resizing the range:
findvalue.resize(x).EntireRow.Delete
 
Solution

Forum statistics

Threads
1,136,284
Messages
5,674,841
Members
419,530
Latest member
undisclosed

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
Top