Delete Identified Rows

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I am trying to use VBA to delete specified row. I want to delete from row 16 down to a dynamic number.

I am using =COUNTA(PartTask_Table[ItemId]) in cell D14. This tells me how many rows I have in the table.

I am trying this code but the "Rows(“fromrow:torow”).EntireRow.Delete" is colored red in my code.

Code:
Sub TestThis()

Dim fromrow As String
Dim torow As String

'On Error Resume Next ‘Blanket error handling

fromrow = Sheet9.Range("16")
torow = Sheet9.Range("D14").Value
Rows(“fromrow:torow”).EntireRow.Delete

End Sub

Also how could I use this to enter/insert X number of rows?

Thanks for the help
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Solved

In Sheet2.Range("B12") I have a CountA formula

Code:
Sub InsertRows()

Dim iRow As Long

    iRow = Sheet2.Range("B12").Value
    
     '   If Sheet2.Range("B12").Value > 0 Then
        
        Sheet9.Select
    
          Range("A15").EntireRow.Offset(1).Resize(iRow).Insert Shift:=xlDown
    
      '  Else
    
'End If
    
End Sub
 
Upvote 0
Solution
All you really needed was this:

VBA Code:
Rows(fromrow & ":" & torow).Delete
OR
VBA Code:
Range(fromrow & ":" & torow).Delete
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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