提问人:jamesrnz 提问时间:9/24/2023 最后编辑:jamesrnz 更新时间:9/24/2023 访问量:43
按顺序从一个子移动到下一个子,在原始帖子中添加了缺少的子 aMoveHTotals()
Move sequentially from one sub to the next sub, ADDED missing Sub aMoveHTotals() in original post
问:
我使用了不同的方法从一个潜艇移动到下一个潜艇或另一个潜艇,没有问题。但是我很难让这个工作
我用过 CALL、GOTO、MOVE RANGE、FIND,运气不好。 我想知道我是否与另一个变量或范围发生冲突。 我已经包含了上一个和下一个子的代码。到目前为止,我在项目中大约有 300 行代码。 SUB ColAInsertrow() 是不会移动到 SUB aMoveHTotals 的 SUB
Sub aGToOColDelete()
Range("g1:g1000000").Clear
Range("i1:i1000000").Clear
Range("j1:j1000000").Clear
Range("k1:k1000000").Clear
Range("l1:l1000000").Clear
Range("m1:m1000000").Clear
Range("n1:n1000000").Clear
Range("o1:o1000000").Clear
Call ColAInsertrow
End Sub
Sub ColAInsertrow() '===================================yay
'Declare Variables
Dim LastRow As Long, FirstRow As Long
Dim Row As Long
Dim moveHTotalsexit As String
With ActiveSheet
'Define First and Last Rows
FirstRow = 1
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'Loop Through Rows (Bottom to Top)
For Row = LastRow To FirstRow Step -1
If .Range("A" & Row).Value <> "" Then
If InStr(.Range("A" & Row).Value, "Transactions for") > 0 Then
.Range("A" & Row).EntireRow.Insert
ElseIf .Range("A" & Row).Value = ("Start") Then GoTo moveHTotalsexit
End If
End If
Next Row
End With
moveHTotalsexit:
'Call aMoveHTotals
Exit Sub
Call aMoveHTotals
End Sub
Sub aMoveHTotals()'I LEFT THIS OUT OF MY FIRST POST ***
Dim ws As Worksheet: Set ws = ActiveSheet' ***
Dim rg As Range: Set rg = ws.UsedRange' ***
aMoveHTotalsx rg, "Date: 8/30/2023", 1, , 0, True' ***
End Sub ' ***
Sub aMoveHTotals( _
ByVal searchRange As Range, _
ByVal SearchPattern As String, _
ByVal SearchColumn As Long, _
Optional ByVal RowOffset As Long = 0, _
Optional ByVal ColumnOffset As Long = 0, _
Optional ByVal ShowMessages As Boolean = False)
'Argumented (An Improvement) - A Method
Const MoveHTotalsX As String = "Totals for date:*"
答:
0赞
taller
9/24/2023
#1
Exit Sub
立即退出 Sub 过程。这是在.Call ..
顺便说一句,最好保留一个新行,尽管它在你的代码中有效。GoTo moveHTotalsexit
'Loop Through Rows (Bottom to Top)
For Row = LastRow To FirstRow Step -1
If .Range("A" & Row).Value <> "" Then
If InStr(.Range("A" & Row).Value, "Transactions for") > 0 Then
.Range("A" & Row).EntireRow.Insert
ElseIf .Range("A" & Row).Value = "Start" Then
GoTo moveHTotalsexit ' **
End If
End If
Next Row
End With
moveHTotalsexit:
'Call aMoveHTotals
' Exit Sub ' **
Call aMoveHTotals
评论
0赞
jamesrnz
9/24/2023
taller_ExcelHome,好吧,它有效,我在 Sub ColAInsertrow() 之后缺少一个 SUB aMoveHTotals()。失去了它编辑或重新排列 Subs,并在沮丧中添加了退出 sub。付费在经过 Sub 时进一步阅读代码,以确保它到达您想要的地方。
评论
Call aMoveHTotals
aMoveHTotals
Optional
aMoveHTotals Range("Xx:Yx"), "myPattern", 2
Exit Sub
Sub
'Call aMoveHTotals