I tried to get data from another separate worksheet. I need to match the new and available model code in the Overall worksheet with the MASTER DATA existing worksheet to get the standard part name. However, I coded and run and no error prompt to me. there is no result too as the Standard part name column are still empty. Below are my code:
Public Sub PopulatePart()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
no_row = Cells(Rows.Count, 1).End(xlUp).Row
no_col = Range("A1",
Range("A1").End(xlToRight)).Count
Worksheets("Overall").Select
For x = 1 To no_col
If Cells(1, x).Value = "Spare Part Code 1" Or
Cells(1, x).Value = "SPARE PART CODE 1" Then
codeCol = x
Exit For
End If
Next x
For x = 1 To no_col
If Cells(1, x).Value = "Standard Part Name" Or
Cells(1, x).Value = "STANDARD PART NAME" Then
nameCol = x
Exit For
End If
Next x
Worksheets("MASTER DATA").Select
no_row_m = Cells(Rows.Count, 1).End(xlUp).Row
For x = 1 To 200
If Cells(1, x).Value = "Spare Part Code 1" Or
Cells(1, x).Value = "SPARE PART CODE 1" Then
codemasCol = x
Exit For
End If
Next x
'Step 2 : Find Repair1 Column
For x = 1 To 200
If Cells(1, x).Value = "Standard Part Name" Or
Cells(1, x).Value = "STANDARD PART NAME" Then
namemasCol = x
Exit For
End If
Next x
'----------------------------------------------------
---------------------
'Populate All Data Based Part name Column and part
code Column
InitProgressBar (no_row)
For x = 2 To no_row
DoEvents
ShowProgress (x)
Worksheets("Overall").Select
Cells(x, codeCol).Select
Cells(x, nameCol).Select
initCode = Cells(x, codeCol).Value
initName = Cells(x, nameCol).Value
Worksheets("MASTER DATA").Select
codeRow = Application.Match(initCode,
Range(Cells(1, codemasCol), Cells(no_row_m,
codemasCol)), 0)
nameRow = Application.Match(initName,
Range(Cells(1, namemasCol), Cells(no_row_m,
namemasCol)), 0)
If IsError(codeRow) = True Then
Else
stdCode = Cells(codeRow, codemasCol +
1).Value
Worksheets("Overall").Select
Cells(x, codeCol + 1) = stdCode
End If
Worksheets("MASTER DATA").Select
If IsError(nameRow) = True Then
Else
NameDes = Cells(nameRow, namemasCol + 1).Value
Worksheets("Overall").Select
Cells(x, nameCol + 1) = NameDes
End If
stdCode = ""
NameDes = ""
Next x
CloseProgressBar
End Sub