VBA를 사용하여 대량의 Excel 파일에서 데이터를 모호하게 가져와 새 표를 생성합니다 (실례 첨부). - (4) 환자의 병례를 결합하여 실례를 대량으로 집계합니다.

3766 단어 Excel
앞의 3편의 소개를 통해 VBA에 대해 더욱 진일보한 인식을 가지게 되었죠.(1) VBA 소개 (2) VBA Excel 간 데이터 읽기 (3) VBA 모호 데이터 찾기
지금 제가 쓴 sub 내용 중 하나를 직접 붙일게요.완전한 내용은 자원에서 보십시오.
Sub GetATValue()

    Debug.Print
    Debug.Print "Start ++++++++++++++++++++++++++++++++++++"
    Dim RootFolder, FolderArray(), FolderName, CurrentFolderPath, FileName, CurrentFilePath

    ' 
     RootFolder = ActiveWorkbook.Path & "\" ' 
     Debug.Print " :" & RootFolder

    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim sheet As Excel.Worksheet
    Dim cAddress

    Set xlApp = New Excel.Application

    Dim PAT

    Dim startRow, endRow
    startRow = 2
    endRow = 359

    Do While startRow <= endRow

        FileName = Cells(startRow, 1)
        CurrentFilePath = RootFolder & FileName
        Debug.Print CurrentFilePath

        ' 
        ' excel 
        Set xlBook = xlApp.Workbooks.Open(CurrentFilePath)

        ' sheet
        Set sheet = xlBook.Worksheets(1)

            'AT
            With sheet.Range("A15:C24")
                Set c = .Find("AT", LookIn:=xlValues)
                If Not c Is Nothing Then
                    tempRow = c.Row

                    PAT = ""

                    PAT = sheet.Cells(c.Row, c.Column + 1)
                    If PAT = "" Then PAT = sheet.Cells(c.Row, c.Column + 2)
                    If PAT = "" Then PAT = sheet.Cells(c.Row, c.Column + 3)

                End If
            End With

            xlBook.Close False

            Cells(startRow, 4) = PAT

        startRow = startRow + 1
    Loop

    Debug.Print "End ++++++++++++++++++++++++++++++++++++"
End Sub

좋은 웹페이지 즐겨찾기