[英]Loop macro through rows
EDIT: I have cleaned up the code as seen below. 编辑:我清理了代码,如下所示。 I am trying to find a way to execute the code with simply adding 1 to row in the offset ranges.
我试图找到一种方法,只需在偏移量范围内的行中加1即可执行代码。 Is this possible??
这可能吗?? enter image description here
在此处输入图片说明
What I am trying to accomplish: 我要完成的工作:
End 结束
Sub Find_Data() Dim datatoFind As String, MySheet As String, FV As String Dim aSh As Worksheet, fSh As Worksheet Dim firstResult As Range Dim secondResult As Range Dim rng As Range Dim LeftCell As Range Dim leftValue As String Set rng = Cells.Find(What:="Wage QRE Exp", after:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False) Set LeftCell = rng.Offset(0, -1) leftValue = LeftCell.Value If leftValue = "Ref." Then Set findValue = rng.Offset(1, 0) Set aSh = Sheet1 datatoFind = findValue sheetCount = ActiveWorkbook.Sheets.Count If Len(datatoFind) = 0 Or Not IsNumeric(datatoFind) Then Exit Sub For counter = 1 To sheetCount Sheets(counter).Activate Set firstResult = Cells.Find(What:=datatoFind, after:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False) Set secondResult = Cells.FindNext(after:=firstResult) Debug.Print secondResult.Address If Not firstResult Is Nothing Then MySheet = IIf(InStr(secondResult.Parent.Name, "."), Split(secondResult.Parent.Name, ".")(0), Split(secondResult.Parent.Name)(0)) FV = MySheet & "." & pageNum(secondResult) Else End If Next counter With rng.Offset(1, -1) .Value = FV .Font.Name = "Times New Roman" .Font.Bold = True .Font.Size = "10" .Font.Color = vbRed .HorizontalAlignment = xlRight .VerticalAlignment = xlCenter End With End If
End Sub 结束子
Your code is a little hard to follow because you don't indent very much (I edited that) and there are no comments. 您的代码有点难以理解,因为您缩进得很少(我对此进行了编辑),并且没有注释。 So I'm not sure what section you want to repeat.
因此,我不确定您要重复哪个部分。
Generally, I suggest a Do loop. 通常,我建议执行Do循环。 And identify the last row by its contents, not its color.
并根据其内容而不是颜色来标识最后一行。
Set ColAcell
to be Cell A5, then: 将
ColAcell
设置为Cell A5,然后:
Do Until ColAcell.value = "Total"
... (your code to process the row) ...
Set ColAcell = ColAcell.offset(1,0)
Loop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.