excel:macro_display_a_message_to_the_user
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
excel:macro_display_a_message_to_the_user [2016/07/11 11:24] – created peter | excel:macro_display_a_message_to_the_user [2016/07/11 11:25] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Microsoft Excel - Macro Delete unused Rows and Cols ====== | ||
- | |||
- | Delete all unused rows and columns in the sheet. | ||
- | |||
- | <code excel> | ||
- | ' Delete all unused rows and columns in the sheet. | ||
- | ' Note: This code may not work correctly if the worksheet contains merged cells. | ||
- | Sub DeleteUnusedOnSheet(ws As String) | ||
- | |||
- | Dim myLastRow As Long | ||
- | Dim myLastCol As Long | ||
- | Dim wks As Worksheet | ||
- | |||
- | With Worksheets(ws) | ||
- | myLastRow = 0 | ||
- | myLastCol = 0 | ||
- | On Error Resume Next | ||
- | myLastRow = _ | ||
- | .Cells.Find(" | ||
- | LookIn: | ||
- | searchdirection: | ||
- | searchorder: | ||
- | myLastCol = _ | ||
- | .Cells.Find(" | ||
- | LookIn: | ||
- | searchdirection: | ||
- | searchorder: | ||
- | On Error GoTo 0 | ||
- | |||
- | If myLastRow * myLastCol = 0 Then | ||
- | .Columns.Delete | ||
- | Else | ||
- | .Range(.Cells(myLastRow + 1, 1), _ | ||
- | .Cells(.Rows.Count, | ||
- | .Range(.Cells(1, | ||
- | .Cells(1, .Columns.Count)).EntireColumn.Delete | ||
- | End If | ||
- | End With | ||
- | |||
- | End Sub | ||
- | </ | ||
excel/macro_display_a_message_to_the_user.1468236257.txt.gz · Last modified: 2020/07/15 09:30 (external edit)