I have several worksheets with data that goes up to 20,000 rows and 60 columns. The entries for a particular column (column W) were not properly entered and therefore a lot of the data have shifted to other columns. For instance instead of Column W you could find the correct entry either in Column Z, U, T, V, X etc. The data in column W should have only 2 characters; the first character should be a number and the second character should be a text (one of the alphabet. Examples are 2B, 5A, 3H, 4F). I wrote the macro below to loop through all the cells matching the content with a range where I have keyed all the possible data that could appear under column W. Where it find match it copies the content to a new range "BK". On the other hand where there is no correct entry on that row then it puts "NULL" in in there. However the macro doesn't seem to work. I need help.
Code:
Sub FindOutletType()
Dim MasterList As Range
Dim I As Integer
Dim J As Integer
Dim FinalRow As Long
Dim FoundRow As Variant
On Error Resume Next
'get the ranges from the user.
'The above on error handles cancel being selected
Set MasterList = Application.InputBox( _
prompt:="Select the range to look for type of outlet mapping", _
Type:=8)
'if no range supplied, exit macro
If MasterList Is Nothing Then End
'restrict the ranges to the used range on the sheet in case entire
'columns selected above
Set MasterList = Intersect(MasterList, ActiveSheet.UsedRange)
'rotate through each cell and see if it is in the first range
FinalRow = Cells(65536, 1).End(xlUp).Row
For I = 2 To FinalRow
For J = 1 To 55
'check only non-blank cells
If Application.Trim(Cells(I, J)) <> "" Then
'reset Err for each loop
Err = 0
'use the match function to see if there is a match. Using a value
'of Zero for the last argument means that an exact match is required
FoundRow = Application.Match(Cells(I, J).Value, MasterList, 0)
'If a match is found Err stays zero; Copy the cell in that case
If Err = 0 Then
Cells(I, J).Copy Destination:=Cells(I, "BK")
End If
End If
Next J
FoundRow = Application.Match(Cells(I, "BB").Value, MasterList, 0)
If Err <> 0 Then
Cells(I, "BK").Value = "NULL"
End If
Next I
End Sub