0

ユーザー指定の番号より下のすべての行を削除するマクロを見つけようとしています。たとえば、ユーザーは「19」を入力し、マクロは行20以下を削除します。私は本当に助けに感謝します。

ありがとう!

4

3 に答える 3

3

これを試して。私は使用し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
于 2012-07-24T17:22:48.567 に答える
0

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
于 2012-07-24T17:04:04.527 に答える
-1

これでうまくいくはずです:

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
于 2012-07-24T16:57:03.177 に答える