将多个子系统合并为一个VBA子系统
我对VBA、这个论坛和一般编程都很陌生。我有一个工作表,我已经设法谷歌和调整某些代码行根据我的要求 我的问题是我总共有三个子系统,必须一步一步地运行每个VBA脚本。我希望将所有三个VBA脚本合并为一个脚本。(第1步+第2步+第3步=一个子组件中的所有组件) 您能告诉我如何将这些多个VBA脚本或子脚本组合在一个子脚本的umbrella下,这样我只需运行一次而不是三次VBA脚本将多个子系统合并为一个VBA子系统,vba,excel,Vba,Excel,我对VBA、这个论坛和一般编程都很陌生。我有一个工作表,我已经设法谷歌和调整某些代码行根据我的要求 我的问题是我总共有三个子系统,必须一步一步地运行每个VBA脚本。我希望将所有三个VBA脚本合并为一个脚本。(第1步+第2步+第3步=一个子组件中的所有组件) 您能告诉我如何将这些多个VBA脚本或子脚本组合在一个子脚本的umbrella下,这样我只需运行一次而不是三次VBA脚本 '---------Step1---------------------------------------- '----
'---------Step1----------------------------------------
'----Run the macro press F5-----
'========================================================================
' DELETES ALL ROWS FROM F DOWNWARDS WITH THE WORDs " " IN COLUMN F
'========================================================================
Sub DeleteRowWithContents()
Last = Cells(Rows.Count, "F").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "F").Value) = "Ja" Or (Cells(i, "F").Value) = "Unbearbeitet" Or (Cells(i, "F").Value) = "-" Or (Cells(i, "F").Value) = "" Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "A").EntireRow.Delete
End If
Next i
End Sub
'-------------------------------Step 2--------------------
'---Run the macro, press F5. The macro compares the row contents in column A and if found a match deletes one of the results--
Sub btest()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Range("A" & i).Value = Range("A" & i - 1).Value Then Rows(i).Delete
Next i
End Sub
'-----------------Step 3---------
'--------Delete Unwanted Columns and adjust the column width----
Sub sbVBS_To_Delete_EntireColumn_For_Loop()
Dim iCntr
Dim kCntr
Dim jCntr
For iCntr = 1 To 4 Step 1
Columns(2).EntireColumn.Delete '-----Del unwanted columns----
Next
For kCntr = 1 To 3 Step 1
Columns(3).EntireColumn.Delete
Next
For jCntr = 1 To 8 Step 1
Columns(4).EntireColumn.Delete
Next
ActiveSheet.Columns("A").Columnwidth = 20 '----Adjust Column width---
ActiveSheet.Columns("C").Columnwidth = 25
ActiveSheet.Columns("E").Columnwidth = 25
End Sub
应该这样做
或者,您可以使用Private
修饰符作为其他Sub的前缀,这样它们就不会出现在“宏”窗口中(电子表格视图中的ALT+F8),并且您只在此处列出了Main
或者,您也可以让其他3个step SUB采用虚拟可选参数,以便在宏对话框中隐藏它们。@vba4all-非常感谢。它就像一个符咒。我如何解决这个问题 @未来研究人员-这就是代码的样子
Sub Main()
'========================================================================
' DELETES ALL ROWS FROM F DOWNWARDS WITH THE WORDs " " IN COLUMN F
'========================================================================
Last = Cells(Rows.Count, "F").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "F").Value) = "Ja" Or (Cells(i, "F").Value) = "Unbearbeitet" Or (Cells(i, "F").Value) = "-" Or (Cells(i, "F").Value) = "" Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "A").EntireRow.Delete
End If
Next i
'---Run the macro, press F5. The macro compares the row contents in column A and if found a match deletes one of the results and the complete row--
Dim LR As Long, x As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For x = LR To 2 Step -1
If Range("A" & x).Value = Range("A" & x - 1).Value Then Rows(x).Delete
Next x
'--------Delete Unwanted Columns and adjust the column width----
Dim lCntr
Dim kCntr
Dim jCntr
For lCntr = 1 To 4 Step 1
Columns(2).EntireColumn.Delete '-----Del unwanted columns here the col b,c,d, e is to be deleted----
Next
For kCntr = 1 To 3 Step 1
Columns(3).EntireColumn.Delete '--enable or disable this loc if you dont wish to further delete cols---
Next
For jCntr = 1 To 8 Step 1
Columns(4).EntireColumn.Delete '--enable or disable this loc if you dont wish to further delete cols---
Next
ActiveSheet.Columns("A").ColumnWidth = 20 '----Adjust Column width---
ActiveSheet.Columns("C").ColumnWidth = 25
ActiveSheet.Columns("E").ColumnWidth = 25
End Sub
Sub Main()
'========================================================================
' DELETES ALL ROWS FROM F DOWNWARDS WITH THE WORDs " " IN COLUMN F
'========================================================================
Last = Cells(Rows.Count, "F").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "F").Value) = "Ja" Or (Cells(i, "F").Value) = "Unbearbeitet" Or (Cells(i, "F").Value) = "-" Or (Cells(i, "F").Value) = "" Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "A").EntireRow.Delete
End If
Next i
'---Run the macro, press F5. The macro compares the row contents in column A and if found a match deletes one of the results and the complete row--
Dim LR As Long, x As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For x = LR To 2 Step -1
If Range("A" & x).Value = Range("A" & x - 1).Value Then Rows(x).Delete
Next x
'--------Delete Unwanted Columns and adjust the column width----
Dim lCntr
Dim kCntr
Dim jCntr
For lCntr = 1 To 4 Step 1
Columns(2).EntireColumn.Delete '-----Del unwanted columns here the col b,c,d, e is to be deleted----
Next
For kCntr = 1 To 3 Step 1
Columns(3).EntireColumn.Delete '--enable or disable this loc if you dont wish to further delete cols---
Next
For jCntr = 1 To 8 Step 1
Columns(4).EntireColumn.Delete '--enable or disable this loc if you dont wish to further delete cols---
Next
ActiveSheet.Columns("A").ColumnWidth = 20 '----Adjust Column width---
ActiveSheet.Columns("C").ColumnWidth = 25
ActiveSheet.Columns("E").ColumnWidth = 25
End Sub