2015-02-04 4 views
0

내 목표는 특정 조건으로 WorkbookA에서 WorkbookA로 워크 시트 (ws1 ... wsn)를로드하는 것입니다. WorkbookA에 여러 워크 시트가 있습니다.배열 대 테이블 비교

상태 :
내가 가지고 로딩을 무시하는 워크 시트 이름을 나열 WorkbookB의 테이블 (tblList) (예를 들어 내가 WS2를로드하지 않으, WS4).

Set SourceDataWorkbook = Workbooks.Open(vSrcFileName) 
validationProd = SourceDataWorkbook.Sheets.Count 

ReDim arrsNames(validationProd) 
For i = 1 To validationProd 
sName = "" 

If fCheckSheet(SourceDataWorkbook, SourceDataWorkbook.Sheets(i).Name) Then 
    sName = SourceDataWorkbook.Sheets(i).Name 
    If Len(Trim(sName)) > 30 Then 
    sName = Mid(sName, 1, 29) 
End If 
    arrsNames(i - 1) = sName 
    outputWorkbook.Sheets.Add(After:=outputWorkbook.Worksheets(i + 3)).Name = _ 
     sName + "_P" 
    SourceDataWorkbook.Sheets(i).Activate 
Else 
    ErrorStatus = "Source Sheet not found " 
    msgBoxReturn = MsgBox(ErrorStatus & SourceDataWorkbook.FullName, _ 
     vbExclamation + vbOKCancel) 
    GoTo TheExit: 
End If 

요구 사항을 달성하는 데 도움을주십시오.

답변

1

코드에 걸려있는 내용이 많습니다 (For LoopIf Statements).
난 당신이 부하에 의해 무슨 뜻인지 모르지만 당신이 원하는 것은 목록 (WorkbookB에서 시트 테이블)하지 WorkbookA에서 워크 시트를 복사 할 경우, 아래 시도 할 수 있습니다 : WorksheetB에서

코드 : 그렇지 않은 경우, 아래처럼 헤더를 포함해야한다

enter image description here

:

Dim sourcewb As Workbook, destwb As Workbook 
Dim ws As Worksheet 
Set sourcewb = Workbooks("workbookname") 'or using Open method 
Set destwb = ThisWorkbook 'contains your table 

For Each ws In sourcewb.Sheets 
    If IsError(Application.Match(ws.Name, Sheet1.Range("tblList"), 0)) Then 
     ws.Copy , destwb.Sheets(destwb.Sheets.Count) 'copy after last sheet 
    End If 
Next 

당신이 단지 1 열 아래 등으로 테이블을 가정 한 것입니다

If IsError(Application.Match(ws.Name, Sheet1.Range("tblList[List]"), 0)) Then 

Sheet1은 테이블이 들어있는 워크 시트 코드 이름입니다.
destwb.Sheets("Sheet1") 또는 시트에있는 이름으로 바꿀 수 있습니다.
이게 너가하려는거야? HTH.

1

대체 솔루션 L42. abpve 질문은 사전을 사용하여 구현할 수 있습니다.

위 함수

Public Function ExclutionDict(Table As String) As Dictionary 

Dim rngTable As Range 
Dim arr As Variant 
Dim Dict As Dictionary 
Dim Count As Long 
Dim tblIgnoreLoad As String 
Dim lo As Excel.ListObject 
Dim test As String 

If Table = "tblIgnoreLoad" Then 
Set lo = ShControl.ListObjects("tblIgnoreLoad") 
Set rngTable = lo.DataBodyRange 

    arr = rngTable.Value 
    Set Dict = New Dictionary 

    For Count = LBound(arr, 1) To UBound(arr, 1) 
    If Len(arr(Count, 1)) <> 0 Then 
     Dict.Add arr(Count, 1), Count 
    End If 
    Next Count 
End If 
Set ExclutionDict = Dict 
End Function 

가 요구

Dim temp As Dictionary 
    Set temp = ShControl.ExclutionDict("tblIgnoreLoad") 

    If temp.Exists(SourceDataWorkbook.Sheets(i).name) Then 
     'Do Nothing 

    Else 
    ' Do you usual copy/load 
end if 

테이블은 사전에 변환되어 목록 배열로 촬영을 일치하도록 실행될 수있다. 워크 시트가 사전에 존재하는지 확인하기 위해 조건을 검증합니다. 다른 사본.

참고 : 사전 속성을 사용하려면 Microsoft Scripting Runtime 참조를 추가하는 것을 잊지 마십시오.

감사합니다.