• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Headers not match then cut paste that file

Abhijeet

Active Member
Hi

Headers are in row 10 same Column that headers i want if any file headers not match then that file i want cut paste in different folder. please tell me how to do this
 

Attachments

  • Match Headers.xlsx
    8 KB · Views: 3
I'm not sure if I understand your requirement here. Can you give bit more detail on what this Row 10 headers are compared to? And what sort of data are expected to go under each header (in what format?).

FYI - If you are not dead set on Excel VBA. Moving files are much easier and often safer with Command Line batch file or with PowerShell script. These tasks can easily scheduled, whereas Excel VBA is much more complicated to code and schedule. See links.

http://www.computerhope.com/movehlp.htm
http://stackoverflow.com/questions/...ew-locations-based-on-file-name-in-powershell
 
Standard Format of file is what i am uploaded.I want if Headers are not in Row 10 & in this sequence then that file i want cut paste in different folder so i am upload only headers in attach file i want to match the headers please tell me how to do this
 
I tried to do this Sheet1 Header match with sheet2 but i want selected folder files if any files header not match then cut paste that file in particular folder can any one help me in this
Code:
Sub MatchHeader()

'VARIABLE NAME                'DEFINITION
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


'Change the names to match your sheetnames:
Set SourceSheet = Sheets("Sheet1")
Set TargetSheet = Sheets("Sheet2")


With TargetSheet
    Set ColHeaders = .Range("A10:L10") '.Range(.Cells(1, 1), .Cells(1, .Columns.Count).End(xlToLeft)) 'Or just .Range("A1:C1")
    Set Rng = .Cells(.Rows.Count, 1).End(xlUp).Offset(1) 'Shoots up from the bottom of the sheet untill it bumps into something and steps one down
End With


With SourceSheet
    Set MyDataHeaders = .Range("A10:L10")
   
'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
            MsgBox "Can't find a matching header name for " & c.Value & vbNewLine & "Make sure the column names are the same and try again."
            Exit Sub    'The code exits here if thereäs no match for the column header
        End If
    Next c
End With


End Sub
 
Hi
I am trying to loop files in folder match header if not then copy paste that file in new folder. Please help me to loop all sheets in files

in this part macro stop i want go to next file please tell me what changes in this also

Code:
For Each c In MyDataHeaders
        If Application.WorksheetFunction.CountIf(ColHeaders, c.Value) = 0 Then
            'MsgBox "Can't find a matching header name for " & c.Value & vbNewLine & "Make sure the column names are the same and try again."
            Workbooks(files).Close
            FileCopy folder & files, DestinationDir & files
            Kill folder & files
            Exit Sub    'The code exits here if thereäs no match for the column header
        End If
    Next c
End With
 

Attachments

  • Match-Headers loop files.xlsm
    21.9 KB · Views: 2
Back
Top