Hi,
I have to validate all the xls files in C:\Validate folder, all the xls files have two worksheets i.e
Master Data worksheet and Relation Data worksheet.
Master data worksheet should have 6 columns, if it has more than 6 or less than 6 columns that particular xls has to be moved to C:\Void folder.
Relation Data worksheet should have 23 columns if it has more than 23 or less than 23 columns that particular xls has to be moved to C:\Void folder.
If any one of the worksheets are having improper range that has to be moved to c:\Void folder.
I am using the below code for validating the master data worksheet, I want to add the validation for Relation Data worksheets as well.
Please tell me how can I add the second sheet for validation,do I need to add some case statement or do I need to so some looping for this.
Sub File_Validation()
Dim ColumnCount As Long
Dim Filename As String
Dim Filepath As String
Dim LastColumn As Long
Dim MoveTo As String
Dim NewFilename As String
Dim OldFilename As String
Dim Rng As Range
Dim Wks As Worksheet
Dim Wkb As Workbook
Filepath = "C:\Validate"
Filename = "*.xls*"
MoveTo = "C:\Void"
Filename = Dir(Filepath & "\" & Filename)
Do While Filename <> ""
Set Wkb = Workbooks.Open(Filename)
For Each Wks In Wkb.Worksheets
ColumnCount = 0
Set Rng = Wks.Cells.Find("*", , xlValues, xlPart, xlByColumns, xlNext, False)
If Not Rng Is Nothing Then
FirstColumn = Rng.Column
Set Rng = Wks.Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious, False)
If Not Rng Is Nothing Then
ColumnCount = Rng.Column - FirstColumn
Else
ColumnCount = 1
End If
End If
If ColumnCount <> 6 Then
OldFilename = Wkb.FullName
NewFilename = MoveTo & "\" & Wkb.Name
Wkb.Close SaveChanges:=False
Name OldFilename As NewFilename
Exit For
End If
Next Wks
Filename = Dir()
Loop
End Sub
Regards,
Shruthi
Bookmarks