【发布时间】:2019-07-03 22:53:59
【问题描述】:
我真的不太懂VBA,所以请耐心等待。
我有一个分配到特定航班 (LEGID) 的人员列表,我想将这些人员 (工作表 pax) 复制到另一个工作表中的特定单元格 (temp - 单元格 b15),但它不起作用。
此数据表是来自 salesforce 的查询报告。
Sub pax()
Dim LastRow As Long
Dim i As Long, j As Long
Dim legid As String
Application.ScreenUpdating = False
legid = ThisWorkbook.Worksheets("setup").Range("SelReq").Value
Debug.Print legid
'Find the last used row in a Column: column A in this example
With Worksheets("pax")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
' MsgBox (LastRow)
'first row number where you need to paste values in temp'
With Worksheets("temp")
j = .Cells(.Rows.Count, "a").End(xlUp).Row + 1
End With
For i = 1 To LastRow
With Worksheets("pax")
If .Cells(i, 1).Value = legid Then
.Rows(i).Copy Destination:=Worksheets("temp").Range("a" & j)
j = j + 1
End If
End With
Next i
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
您是否收到错误或没有复制任何内容?
-
如果数据存储在表中,我认为您将希望使用
ListObject而不是循环遍历一个范围。 -
没有错误。只是不要做任何事情。 - @Warcupine
-
我该怎么做? @ZackE
-
看第二个答案Here