1
votes

I have 2 sheets. When entries in in a specific column in ws2 contains the word "UPDATE" it will update ws1 with newer data found in ws2

Private Sub CommandButton1_Click()

Dim LastRow As Long, CurRow As Long, DestRow As Long, DestLast As Long



Dim ws1 As Worksheet, ws2 As Worksheet

Set ws1 = Sheets("Dashboard")
Set ws2 = Sheets("TempHRI")

LastRow = ws2.Range("B" & Rows.Count).End(xlUp).Row
DestLast = ws1.Range("E" & Rows.Count).End(xlUp).Row

For CurRow = 2 To LastRow 'Assumes first row has headers
    If ws2.Range("X" & CurRow) = "UPDATE" Then 'Column that looks up the word "Update" in ws2
        If Not ws1.Range("E15:E" & DestLast).Find(ws2.Range("B" & CurRow).Value, LookIn:=xlValues, LookAt:=xlWhole) Is Nothing Then
            DestRow = ws1.Range("E15:E" & DestLast).Find(ws2.Range("B" & CurRow).Value, LookIn:=xlValues, LookAt:=xlWhole).Row
        End If
        ws1.Range("Q" & DestRow).Value = ws2.Range("N" & CurRow).Value 'assumes supervisor is in column C in both sheets
        ws1.Range("R" & DestRow).Value = ws2.Range("O" & CurRow).Value 'assumes director is in column D in both sheets
    End If
Next CurRow

End Sub

but I'm getting a type mismatch on line:

If ws2.Range("X" & CurRow) = "UPDATE" Then

thanks in advance.

1

1 Answers

0
votes

try:

If ws2.Range("X" & CurRow).Text = "UPDATE" Then