如何使用VBA代码提取excel工作表数据

2025-03-12 18:14:06
推荐回答(1个)
回答1:

代码复制到 报表 代码窗口,不要弄反了哦
Sub 获取数据()
x = WorksheetFunction.Match([A1], Sheets("数据").Range("B:B"), 0)
arr = Sheets("数据").Range("d" & x & ":" & "h" & x)
[b4].Resize(1, 5) = arr
[b5] = Sheets("数据").Cells(x, "i")
End Sub

Sub 获取数据()
y = WorksheetFunction.CountIf(Sheets("数据").Range("B:B"), [a1])
If y = 0 Then
MsgBox "日期输入错误"
Exit Sub
End If
x = WorksheetFunction.Match([a1], Sheets("数据").Range("B:B"), 0)
arr = Sheets("数据").Range("d" & x & ":" & "h" & x)
[b4].Resize(1, 5) = arr
[b5] = Sheets("数据").Cells(x, "i")
End Sub