HI Arnel, I have tried with a code to identify the headers presence in sheet2 of column 2. Is there any way you can suggest to get corresponding c3 valueOption Explicit Private Sub Workbook_AfterSave(ByVal Success As Boolean) Dim SourceSheet As Worksheet 'The data to be copied is here Dim TargetSheet As Worksheet 'The data will be copied here Dim ColHeaders As Range 'Column headers on Target sheet Dim MyDataHeaders As Range 'Column headers on Source sheet Dim DataBlock As Range 'A single column of data Dim c As Range 'a single cell Dim Rng As Range 'The data will be copied here (="Place holder" for the first data cell) 'Dim i As Integer Dim MyRow As Integer Dim MyCol As Integer Dim check_type As String 'Change the names to match your sheetnames: Set SourceSheet = Sheets("Service User") 'sheet1 Set TargetSheet = Sheets("User Details") 'sheet2 With TargetSheet ' Set ColHeaders = .Range(.Cells(2, 2), .Cells(1, .Columns.Count).End(xlToLeft)) 'Or just .Range("A1:C1") ' Set Rng = .Cells(.Rows.Count, 2).End(xlUp).Offset(1) 'Shoots up from the bottom of the sheet untill it bumps into something and steps one down Set ColHeaders = .Range("B2:B26") ' .Range(.Cells(1, 1), .Cells(1, .Rows.Count).End(xlToLeft)) 'Or just .Range("A1:C1") Set Rng = .Cells(.Rows.Count, 1).End(xlUp).Offset(1) End With With SourceSheet Set MyDataHeaders = .Range("A1:AB1") End With 'Makes sure all the column names are the same: 'Each header in Source sheet must have a match on Target sheet (but not necessarily in the same order + there can be more columns in Target sheet) For Each c In MyDataHeaders If Application.WorksheetFunction.CountIf(ColHeaders, c.Value) <> 0 Then ' check_type = TargetSheet.Cells(c, 3).Value ' check_type = Worksheets("User Details").Cells(c.Row, "C3").Value ' MsgBox check_type ' MyRow = Worksheets("User Details").Range(c.EntireRow.Rows).Value ' MyCol = Worksheets("User Details").Range("C3").Value ' MsgBox Worksheets("User Details").Cells(MyRow, MyCol).Select c.Interior.Color = vbRed MsgBox _ "found a matching header name for " & c.Value & vbNewLine & "Make sure the column names are the same and try again." 'The code exits here if thereäs no match for the column header End If Next c End If End Sub




Reply With Quote