使用下面的代碼。運行宏'選擇'來選擇級別。此代碼刪除整列,其中條件爲真
Sub Choose()
l = InputBox(Prompt:="Enter the level you want", Title:="Level Selection")
If l = 1 Then
Call Level1
ElseIf l = 2 Then
Level2
ElseIf l = "" Then
Else
MsgBox "Incorrect entry.", vbInformation, "Incorrect"
End If
End Sub
Sub Level1()
Application.ScreenUpdating = False
On Error Resume Next
Blad1.Activate
Blad1.Cells.Find(What:="C12", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad1.Columns(i).Delete
Blad2.Activate
Blad2.Cells.Find(What:="C22", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad2.Columns(i).Delete
Blad3.Activate
Blad3.Cells.Find(What:="C32", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad3.Columns(i).Delete
Blad1.Activate
Application.ScreenUpdating = True
End Sub
Sub Level2()
Application.ScreenUpdating = False
On Error Resume Next
Blad1.Activate
Blad1.Cells.Find(What:="C11", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad1.Columns(i).Delete
Blad1.Cells.Find(What:="C13", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad1.Columns(i).Delete
Blad2.Activate
Blad2.Cells.Find(What:="C21", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad2.Columns(i).Delete
Blad2.Cells.Find(What:="C22", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad2.Columns(i).Delete
Blad3.Activate
Blad3.Cells.Find(What:="C33", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad3.Columns(i).Delete
Blad3.Cells.Find(What:="C34", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad3.Columns(i).Delete
Blad3.Cells.Find(What:="C35", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
i = ActiveCell.Column
Blad3.Columns(i).Delete
Blad1.Activate
Application.ScreenUpdating = True
End Sub
請see the file包括宏
是列標題總是將是每個表的第一行? – dash
VBA不是VB6。有錯誤的問題。 – Bob77
嗨! 不,他們會在第6行。 希望你能幫助我。 最好的問候 –