Delete rows after row number from input box

bchaabi

New Member
Joined
Oct 1, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I want to type a number into an input box and delete everything after that row. This is what I have so far but I am getting errors on row 7


1 Sub CutList()
2
3 Dim i As Variant
4 i = InputBox("What size do you want the list to be?")
5
6 With ActiveSheet
7 Rows(i & .Rows.Count).Delete
8 End With
9
10 End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
VBA Code:
Sub CutList()
    Dim i As Long, sh As Worksheet
 
    Set sh = ActiveSheet
 
    With sh
        i = InputBox("What size do you want the list to be?")
        .Range("A" & i + 1 & ":A" & .Cells(.Rows.Count, "A").End(xlUp).Row).EntireRow.Delete
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,874
Messages
6,127,473
Members
449,384
Latest member
purevega

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