Hi ,
I have the below code that I want to tweak , I receive fileswith 820 columns (AEN) and each column has different character lengthrequirement.
EG. Column A ColumnB Column C Etc
Len = 3 Len = 10 Len= 50 Etc
I am trying to think of the easiest way to validate this. Asthere are so many columns I am thinking maybe have the macro import a spreadsheetthat contains all the required field lengths and then have the macro validateeach cell against the imported spreadsheet.
I am just not sure how to do it. Any advice or guidance isgreatly appreciated.
I have the below code that I want to tweak , I receive fileswith 820 columns (AEN) and each column has different character lengthrequirement.
EG. Column A ColumnB Column C Etc
Len = 3 Len = 10 Len= 50 Etc
I am trying to think of the easiest way to validate this. Asthere are so many columns I am thinking maybe have the macro import a spreadsheetthat contains all the required field lengths and then have the macro validateeach cell against the imported spreadsheet.
I am just not sure how to do it. Any advice or guidance isgreatly appreciated.
Code:
Sub Highlight()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Dim sheetName As String
Dim startRow As Integer, startCol As Integer
Dim endRow As Integer, endCol As Integer
Dim row As Integer, col As Integer
Dim c As Integer[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]sheetName = "POL" 'Your sheetname[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]With Sheets(sheetName)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] startRow = 4 'start row for the loop
startCol = 1 'start column for the loop[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] endRow = .UsedRange.SpecialCells(xlCellTypeLastCell).row 'Last Used Row
endCol = .UsedRange.SpecialCells(xlCellTypeLastCell).Column 'Last Used Column[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] c = 0[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] For row = startRow To endRow Step 1 'Loop through rows[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] For col = startCol To endCol - 1 Step 1 'Loop through columns[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] If Len(.Cells(row, col)) > 2 And Len(.Cells(row, col)) < 9 Then 'If value of cell is wrong[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] .Cells(row, col).Interior.Color = vbYellow 'mark cell in red
c = c + 1[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Next col
Next row[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] MsgBox "There were issues with " & c & " entries. See yellow cells" 'Warns that there are errors[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End With[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub