Hi all,
I am trying to create a code where it loops through all the columns within two sheets based on the column header. I need to compare the column headers and if the column header does not match, the code will clear contents of that specific column except the column header and so on... I have attached the code I have so far but it doesn't seem to work accordingly. P.S. this code is part of a larger procedure so I have not shown a lot of the variables that have been listed. I have also attached a sample excel file with the format of the columns. thank you!
With wb.Sheets(destinationSheetName)
lastcolumn = .Cells(columnheader, Columns.count).End(xlToLeft).Column
lastcol = Workbooks(FileName).Sheets(importFile).Cells(columnheader, Columns.count).End(xlToLeft).Column
For count = 1 To lastcolumn
For col = 1 To lastcol
If .Cells(columnheader, count).Value <> Workbooks(FileName).Sheets(importFile).Cells(columnheader, lastcol).Value Then
.Cells(columnheader + 1, count).Resize(.Rows.count - 1).ClearContents
End If
Next col
Next count
End With
Bookmarks