두 Excel 2007 Excelbook 통합 문서가 있습니다. 및 요약입니다. 요약에 rh 파일을 검사하여 그 안에있는 텍스트를 기반으로 특정 열을 찾습니다. 이 열을 찾아 복사하고 요약 시트에 데이터를 보내야합니다.값과 일치하고 다른 통합 문서로 데이터를 복사하는 VBA 선택 열
Sub Main()
' Declare hr workbook file
Dim rh As Excel.Workbook
' initialise hr workbook file
Set rh = Workbooks.Open("C:\Users\AC74338\Desktop\ac\rh")
'select the rh file
rh.Select
'select the open worksheet
Sheets("Open").Select
' search for the column header that matches e.g. "Org Level 6"
OrgLevel6 = WorksheetFunction.Match("Org Level 6", Rows("1:1"), 0)
OrgLevel7 = WorksheetFunction.Match("Org Level 7", Rows("1:1"), 0)
'activate this workbook where the code is
ThisWorkbook.Activate
'paste the data that was copied to this workbook in the NxNOpen worksheet
ThisWorkbook.Sheets("NxNOpen").Columns(OrgLevel6).Copy Destination:=Sheets("Sheet2").Range("A1")
ThisWorkbook.Sheets("NxNOpen").Columns(OrgLevel7).Copy Destination:=Sheets("Sheet2").Range("B1")
End Sub
데이터를 OrgLevel6 변수에 할당 할 때 디버깅을 수행하고 오류가 발생합니다. 누구든지이 문제를 해결하는 방법에 대한 제안이 있습니까? VB에서는 익숙하지 않으므로 간단한 실수 일 수 있습니다.
코드로 편집 한 내용을 추가의 조직 레벨 6 열은 열 K에 있지만이 열 AD를 복사하고, 어떤 제안 왜? –
'Match' 함수에서'Sheets ("Open")'을 가지고 있지만 실제로'Sheets ("NxNOpen")'에서 복사하고 있습니다 - 당신이 일관성있게 만들면 같은' 시트 '를 사용하여 일치시킵니다. – Jordan
멋진 도움말, 내가 잘못된 시트를 참조하고있었습니다. 도움을 주셔서 감사합니다! –