1 line
2.4 KiB
Plaintext
1 line
2.4 KiB
Plaintext
{"ID":"20250909154954-r1japhc","Spec":"2","Type":"NodeDocument","Properties":{"id":"20250909154954-r1japhc","title":"VBA学习笔记","type":"doc","updated":"20250916171010"},"Children":[{"ID":"20250911072908-gtcznc2","Type":"NodeCodeBlock","IsFencedCodeBlock":true,"Properties":{"id":"20250911072908-gtcznc2","updated":"20250911072908"},"Children":[{"Type":"NodeCodeBlockFenceOpenMarker","Data":"```"},{"Type":"NodeCodeBlockFenceInfoMarker","CodeBlockInfo":"dmJh"},{"Type":"NodeCodeBlockCode","Data":"Sub DeleteSubtotalRows()\n ' Declare variables\n Dim ws As Worksheet\n Dim rng As Range\n Dim cell As Range\n Dim lastRow As Long\n Dim i As Long\n Dim deleteCount As Integer\n Dim colToCheck As Integer ' Column number to check (1 for column A, 2 for column B, etc.)\n\n On Error GoTo ErrorHandler\n Application.ScreenUpdating = False ' Turn off screen updating for faster execution\n Application.Calculation = xlCalculationManual ' Set calculation to manual mode\n\n ' Set the worksheet to operate on (default is active sheet)\n Set ws = ActiveSheet\n \n ' Set the column to check (Column A = 1)\n colToCheck = 1\n \n ' Find the last row in the worksheet\n lastRow = ws.Cells(ws.Rows.Count, colToCheck).End(xlUp).Row\n \n deleteCount = 0 ' Initialize counter\n \n ' Loop from last row to first row (to avoid affecting loop when deleting rows)\n For i = lastRow To 1 Step -1\n ' Check if cell contains \"小計\"\n If InStr(1, ws.Cells(i, colToCheck).Value, \"小計\") \u003e 0 Then\n ' Delete entire row\n ws.Rows(i).Delete\n deleteCount = deleteCount + 1\n End If\n Next i\n\n Application.ScreenUpdating = True ' Restore screen updating\n Application.Calculation = xlCalculationAutomatic ' Restore automatic calculation\n \n ' Display processing result\n MsgBox \"Process completed! Deleted \" \u0026 deleteCount \u0026 \" rows containing '小計'.\", vbInformation, \"Completed\"\n \n Exit Sub\n\nErrorHandler:\n Application.ScreenUpdating = True\n Application.Calculation = xlCalculationAutomatic\n MsgBox \"Error occurred: \" \u0026 Err.Description, vbCritical, \"Error\"\nEnd Sub\n"},{"Type":"NodeCodeBlockFenceCloseMarker","Data":"```"}]},{"ID":"20250912142858-eq6vv88","Type":"NodeParagraph","Properties":{"id":"20250912142858-eq6vv88","updated":"20250912142858"}}]} |