New to VBA.
I have a 2 workbook Excel. Programmed successfully a CommandButton on sheet 2 ("PTID_Link_Log"). Now I want to move it to sheet 1 ("Assignment"). Now it only completes actions on sheet 1, nothing on sheet 2. How do I make the code work from sheet 1?
Code:
Appreciate any guidance
I have a 2 workbook Excel. Programmed successfully a CommandButton on sheet 2 ("PTID_Link_Log"). Now I want to move it to sheet 1 ("Assignment"). Now it only completes actions on sheet 1, nothing on sheet 2. How do I make the code work from sheet 1?
Code:
Private Sub CommandButton1_Click()
Dim PTID As Long
Dim LastRow As Long
Dim i As Long
Sheets("PTID_Link_Log").Activate
ActiveSheet.Range("A1:K3335").Select
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Range("D" & i).Value = "" Then
If Range("C" & i).Value <> "" Then
Range("D" & i).Value = Range("C" & i)
End If
End If
If Range("G" & i).Value = "" Then
If Range("F" & i).Value <> "" Then
Range("G" & i).Value = Range("F" & i)
End If
End If
If Range("J" & i).Value = "" Then
If Range("I" & i).Value <> "" Then
Range("J" & i).Value = Range("I" & i)
End If
End If
Next i
Sheets("Assignment").Activate
ActiveSheet.Range("A1:K2").Select
PTID = ActiveSheet.Range("A2").Value
If PTID <> 0 Then
ActiveSheet.Range("C2") = ""
ActiveSheet.Range("E2") = ""
ActiveSheet.Range("G2") = ""
ActiveSheet.Range("A2") = ""
End If
ActiveSheet.Range("A2").Select
End Sub
EndCodeDim PTID As Long
Dim LastRow As Long
Dim i As Long
Sheets("PTID_Link_Log").Activate
ActiveSheet.Range("A1:K3335").Select
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Range("D" & i).Value = "" Then
If Range("C" & i).Value <> "" Then
Range("D" & i).Value = Range("C" & i)
End If
End If
If Range("G" & i).Value = "" Then
If Range("F" & i).Value <> "" Then
Range("G" & i).Value = Range("F" & i)
End If
End If
If Range("J" & i).Value = "" Then
If Range("I" & i).Value <> "" Then
Range("J" & i).Value = Range("I" & i)
End If
End If
Next i
Sheets("Assignment").Activate
ActiveSheet.Range("A1:K2").Select
PTID = ActiveSheet.Range("A2").Value
If PTID <> 0 Then
ActiveSheet.Range("C2") = ""
ActiveSheet.Range("E2") = ""
ActiveSheet.Range("G2") = ""
ActiveSheet.Range("A2") = ""
End If
ActiveSheet.Range("A2").Select
End Sub
Appreciate any guidance