ユーザー指定の番号より下のすべての行を削除するマクロを見つけようとしています。たとえば、ユーザーは「19」を入力し、マクロは行20以下を削除します。私は本当に助けに感謝します。
ありがとう!
これを試して。私は使用しActiveSheet
ました。作業したい任意のシートに設定できます。
Sub Sample()
Dim Ret As Long
Ret = Application.InputBox(Prompt:="Please enter a row number", Type:=1)
If Ret = False Then Exit Sub
With ActiveSheet
.Rows(Ret + 1 & ":" & .Rows.Count).Delete
End With
End Sub
column=1 と Row=1 に、保持する行の番号を入力できます。データは、row=2 に戻るすべての行が削除される前に、rows=deleterows にあります。
Sub Macro1()
'
' Macro1 Macro
'
deleterowsbefore = ActiveSheet.Cells(1, 1)
Rows("2:" & deleterowsbefore - 1).Select
Selection.Delete Shift:=xlUp
End Sub
これでうまくいくはずです:
Sub UserInput()
Dim num As Integer
num = InputBox(Prompt:="Enter the row number.", Title:="Enter Row Number", Default:="Row number")
If (num < 1) Then
GoTo Whoops:
End If
Dim i As Integer
i = 1
Do While i <= num
Rows(1).EntireRow.Delete
i = i + 1
Loop
GoTo Fin:
Whoops:
MsgBox ("You have entered an invalid row number")
Fin:
End Sub