我正试图将数据从称为"kpi"的表中的列复制到单元格H6:H100中名为"表"的表中的特定行。该行取决于KPI表中的两个变量,用户可以从C2:D2中的下拉列表中选择这两个变量。
我已经设法让代码找到正确的行,每次通过搜索列A然后B在"数据"床单但是当涉及到复制粘贴/转置H列时,从"KPI"表格放到"表格"的右行。表会抛出424错误。
我可能遗漏了一些非常明显的东西,所以任何帮助都是感激的。
Sub copy_transpose()
Dim rng_source As Range
Dim Found As Range, Firstfound As String
Dim rngSearch As Range
Dim Criteria As Variant
Set rng_source = ThisWorkbook.Sheets("KPI").Range("H6:H100")
Set rngSearch = Sheets("Table").Range("A:A")
Criteria = Sheets("KPI").Range("C2:D2").Value
Set Found = rngSearch.Find(What:=Criteria(1, 1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Found Is Nothing Then
Firstfound = Found.Address
Do
If Found.EntireRow.Range("B2").Value = Criteria(1, 2) Then Exit Do 'Match found
Set Found = rngSearch.FindNext(After:=Found)
If Found.Address = Firstfound Then Set Found = Nothing
Loop Until Found Is Nothing
End If
If Not Found Is Nothing Then
Application.Goto Found
rng_source.Copy
Sheets("Table").Range(cell.Offset(0, 1), cell.Offset(0, 7)).PasteSpecial Transpose:=True
Else
MsgBox ("Error")
End If
End Sub
我需要更多的咖啡。我没有注意到它引用了"cell"。而不是"发现"。今天我知道了"细胞"。不是一个vba函数,实际上是我在旧代码中标注过的东西,相当于"found"