比较映射 table 然后用数据库改变 headers(第 1 行)

Compare the mapping table and then change with the database headers(row 1)

如何比较 excel 中的映射 table(不同单元格中的值)并将 header 的值映射到我的主数据库。

主数据库:

映射Table:

Tanu 的 Sheet:

它应该映射文件(tanu、sweety、Raju)的 headers(wgt、ht、bmi 等)并将其与主数据库进行比较并将其替换为 header主数据库的 s

 The code written so far
 Sub SelectColumn()
 Dim xColIndex As Integer
 Dim xRowIndex As Integer
   xIndex = Application.ActiveCell.Column
    xRowIndex = Application.ActiveSheet.Cells(Rows.Count, 
     xIndex).End(xlUp).Row
     Range(Cells(2, xIndex), Cells(xRowIndex, xIndex)).Select
   End Sub

打不通

此代码将检查您的映射 table 并在每个工作簿 tanu、sweety 等的每个工作表中替换 headers(它将在范围 A1:Z1000,如果需要更大的范围,请更改它):

Sub foo3()
Dim Wbook As Workbook
Dim wSheet As Worksheet
Dim wb As ThisWorkbook
Set wb = ThisWorkbook
Application.DisplayAlerts = False
LastCol = wb.Sheets("LMal").Cells(1, Columns.Count).End(xlToLeft).Column 'Check how many columns in the Mapping Table
LastRow = wb.Sheets("LMal").Cells(Rows.Count, "A").End(xlUp).Row 'Check how many rows in the Mapping Table
For i = 2 To LastCol
    Filename = "C:\Users\tanu\Desktop\" & wb.Sheets("LMal").Cells(1, i) & ".xlsx" ' Get the Sheet name such as tanu, sweety, etc
    Set Wbook = Workbooks.Open(Filename)
        For x = 2 To LastRow ' loop through rows
        Search = wb.Sheets("LMal").Cells(x, i).Value
        On Error Resume Next
            For Each wSheet In Wbook.Worksheets
                Set strGotIt = wSheet.Cells.Find(What:=Search, After:=wSheet.Cells(1, 1), _
                           LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                           SearchDirection:=xlNext, MatchCase:=True)
                If strGotIt <> vbNullString Then
                   wSheet.Cells(strGotIt.Row, strGotIt.Column).Value = wb.Sheets("LMal").Cells(x, 1).Value 'replace the value in tanu's sheet
                   On Error GoTo 0
                End If

            Next
           On Error GoTo 0
        Next x

Wbook.Close SaveChanges:=True
Application.DisplayAlerts = True
Next i
End Sub