簡體   English   中英

如何從工作簿中的不同工作表中獲取宏拉數據。 Excel VBA

[英]How do I make macro pull data from different sheets within a workbook. Excel VBA

我遇到了一個用於將信息從一個工作表提取到另一個工作表的宏的問題。 我無法弄清楚如何讓宏看看“CurrentSchedule”工作簿中的不同工作表。 當我使用第1行(A行)工作表瀏覽宏時,一切都運行順利,但是當我嘗試通過第二張(B行)運行時,它會超時。 它特別陷入困境

“Order = Range(”W1“)。Offset(Count,0).Value”

SAPorder = InputBox("Enter SAP Order Number:")
ProdLine = InputBox("Enter the sheet# of CurrentSchedule that has this   SAP order number. Example: A line = 1; B = 2")
End Select
Count = 0 'Count is the row in the designated column
Flag = True
Do While Flag
Workbooks("CurrentSchedule.xlsx").Worksheets(ProdLine).Activate
Order = Range("W1").Offset(Count, 0).Value 
If Order = SAPorder Then
nme = Range("B1").Offset(Count, 0).Value 

扔掉那個愚蠢的.activate方法學習如何使用它

Sheets("sheetName").range("rangeName/rangeRange")[optional].cells("cellRow","cellColumn")

它將使您的工作更加輕松,然后您可以使用工作表/范圍/單元格作為對象。

此外,當您使用不帶點和父對齊的范圍/單元格時,您使用活動工作表,這可能是非常不可預測的。 因此,如果你使用上面提到的完整陳述,你就不能犯錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM