Página 1 de 1

Trocar valores em macro ativa

Enviado: 26 Abr 2019 às 04:33
por Angra
Bom dia
Tenho uma duvida, se existe a possibilidade de inserir/trocar alguns valores dentro da macro no vba, a partir da inserção de valores em células na plan :D :D

Re: Trocar valores em macro ativa

Enviado: 30 Abr 2019 às 16:52
por babdallas
Tente assim:
Código: Selecionar todos
Sub Atribuir()

Dim i           As Long
Dim LinIndex    As Long
Dim LinStart    As Long
Dim LinEnd      As Long
Dim NomeBola    As String
Dim NumeroBola  As Long

    With wshBolas
        LinStart = .Range("V31").Value2 'trocar o valor
        LinEnd = .Range("U31").Value2    'trocar o valor
        LinIndex = .Cells(.Range("T31").Value2, 2).Value 'trocar o valor
        NomeBola = Application.Caller
        NumeroBola = VBA.Right(NomeBola, 2)

        For i = 20 To 22
            If .Cells(LinIndex + LinStart - 1, i).Value = Empty Then
                .Cells(LinIndex + LinStart - 1, i).Value = NumeroBola
                Exit For
            End If
        
            If .Cells(LinIndex + LinStart - 1, i).Value = NumeroBola Then
                VBA.MsgBox "Bola repetida"
                Exit For
            End If
        
            If i = 22 Then
                VBA.MsgBox "Limite excedido"
                Exit For
            End If
        Next i
    End With
End Sub

Re: Trocar valores em macro ativa

Enviado: 30 Abr 2019 às 16:53
por babdallas
Segue em anexo a pasta de trabalho.

Re: Trocar valores em macro ativa

Enviado: 30 Abr 2019 às 19:42
por Angra
Obrigado, eh :D :D isso mesmo