私は何か単純なことを見過ごしていると確信していますが、あまりにも多くの時間がかかりました。なぜMAIN
というワークシートを私のImport
以下の手順に従います。 MAINはワークブック内のワークシートです。手続きにシート名を渡す際のタイプの不一致
Import
という共通のプロシージャを使用して、同じワークブック内のワークシートを渡すことができ、ワークシート名をパラメータ引数として渡すだけで、以下の列のセル関係を簡単に配列に格納できます。
Sub Import(sheetname As Worksheet)
'Debug.Print (sheetname)
cName = "Fund ID"
cA = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "CUSIP"
cB = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Description"
cC = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Security Type"
cD = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Currency"
cE = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Price Date"
cF = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Current Price"
cG = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Prior Price"
cH = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Change Price (%)"
cI = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Change Price (%)"
cJ = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "BPS Impact"
cK = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Source"
cL = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
cName = "Comment"
cM = sheetname.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
LastRow = Range("b65000").End(xlUp).Row
For r = 2 To LastRow
Row = Row + 1
aRecon1(Row, 1) = CStr(Cells(r, cA)) 'Fund ID ' added string value method
'aRecon1(Row, 1) = Cells(r, cA) 'Fund ID
aRecon1(Row, 2) = Cells(r, cB) 'CUSIP
aRecon1(Row, 3) = Cells(r, cC) 'Description
aRecon1(Row, 4) = Cells(r, cD) 'Security Type
aRecon1(Row, 5) = Cells(r, cE) 'Currency
aRecon1(Row, 6) = Cells(r, cF) 'Price Date
aRecon1(Row, 7) = Cells(r, cG).Value 'Current Price
'Debug.Print (Cells(r, cG).Value)
Debug.Print (Cells(r, cG).Value)
'Debug.Print (Cells(r, cG))
aRecon1(Row, 8) = Cells(r, cH).Value 'Prior Price
aRecon1(Row, 9) = Cells(r, cI) 'Change Price (%)
aRecon1(Row, 10) = Cells(r, cJ) 'BPS Impact
aRecon1(Row, 11) = Cells(r, cK) 'Source
Debug.Print (Cells(r, cK))
aRecon1(Row, 12) = Cells(r, cL)
Next r
Sheets("Macro").Activate
**このルーチンを実際に**呼び出す**のですか? – Rory
ワークシート名は、ワークシート名ではなく、 'Call Import(WorkSheets(" MAIN "))でなく、' Call Import( "MAIN") ' –
@Rory Sub Main() インポート"MAIN" End Sub – phillipsK