[Solved] VBA code or macro copying cell value [closed]


try this:

Sub AddName()
    Dim lr As Long, i As Long, count As Long
    Dim Team As String, Sport As String, NewPlayer As String

    Team = "Pink Team"
    Sport = InputBox("What Sport do you wish to add a name to?", "Sport")
    NewPlayer = InputBox("What is the name of the player you wish to add?", "New Player")
        With ActiveSheet
            lr = .Range("A" & Rows.count).End(xlUp).Row

            For i = 1 To lr
                If .Range("A" & i).Value = Team And .Range("B" & i).Value = Sport Then
                    .Range("C" & i).Value = .Range("C" & i).Value & ", " & NewPlayer
                    count = count + 1
                End If
            Next i
        End With
    If count = 0 Then MsgBox "The " & Team & " doesnt appear to play " & Sport & " yet."
End Sub

To add the code hit ALT + F11 on your keyboard. Then double click the sheet name (top left) you wish to add the code to & paste the code there.

1

solved VBA code or macro copying cell value [closed]