【发布时间】:2022-01-03 22:02:04
【问题描述】:
尝试执行代码循环,直到 A 列中的最后一个单元格。
尝试使用 For 但不理解某些内容并尝试使用 Do Until。它有点工作,但在粘贴详细信息代码后卡住了。
我的代码如下有谁知道为什么会卡住?
Sub Pivot()
Dim lastrow_blank As Long
Dim lastrow_blankA As Long
Dim lastrow_blankselection As Long
Dim a As Long
Sheets("Report").Select ' Select sheet '
ThisWorkbook.RefreshAll ' Refresh Pivot '
Data = Date - 1 ' Yesterdays date '
lastrow_blank = Sheets(1).Cells(Rows.Count, "B").End(xlUp).Row + 1 ' first blank cell in column B '
lastrow_blankA = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row + 1 ' first blank cell in column A '
lastrow_blankselection = CDate(Cells(lastrow_blank, 1).Value) ' Value selection of the last low in column A '
a = Range("A2").Value
Range("A3:A" & CLng(Date - a + 1)).Value = Evaluate("Row(" & a + 1 & ":" & CLng(Date) & ")") ' Paste date's until yesterday in column A '
Do Until IsEmpty(Cells(lastrow_blank, 1)) ' loop starts '
If Cells(lastrow_blank, 1) = "" Then ' If first cell in column B is empty then '
MsgBox "Info" ' Message if cell is empty '
Exit Sub
Else
ActiveWorkbook.SlicerCaches("NativeTimeline_Value_Date").TimelineState. _
SetFilterDateRange lastrow_blankselection, lastrow_blankselection ' this code selects a timeline date '
ActiveWorkbook.SlicerCaches("NativeTimeline_Good_Date").TimelineState. _
SetFilterDateRange lastrow_blankselection, lastrow_blankselection ' this code selects a timeline date '
Sheets("Report").Range("O4:Z4").Copy ' Copy cells that returns details from Pivot '
Cells(lastrow_blank, 2).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False ' Paste details from Pivot to celected cells'
' when the code is launched it loops first time correctly and then after the paste code it gets stuck i think because it does nothing'
' After I cancel the code paste code get highlited in yellow '
End If
Loop
End Sub
【问题讨论】:
-
你需要增加一些东西,现在你只是循环通过第一个单元格