Notifications
Clear all

Procurar, somar na segunda e terceira coluna

5 Posts
2 Usuários
0 Reactions
990 Visualizações
(@rafnakb)
Posts: 0
New Member
Topic starter
 

Boa tarde.
Preciso de um código que procure o correspondente na primeira coluna e some os valores da TxtBox com os valores da segunda e terceira coluna ao clicar no botão.
Por enquanto tenho isso:

Private Sub CommandButton1_Click()

Dim l2 As Integer
Dim l As Integer


rang = Range("A1:A" & Cells(Rows.Count, 1)).End(xlUp).Row

For l = 1 To UBound(rang, 1)

        If rang(l, 1) = TxtBox1.Value Then
        
        l2 = l

        End If

Next
Cells(l2, 2).Value2 = Cells(l2, 2).Value2 + TxtBox2.Value
Cells(l2, 3).Value2 = Cells(l2, 3).Value2 + TxtBox3.Value
End Sub

Pderiam me ajudar ?

 
Postado : 28/07/2016 11:44 am
(@edcronos2)
Posts: 0
New Member
 

mude
rang = Range("A1:A" & Cells(Rows.Count, 1)).End(xlUp).Row
para
rang = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value2
acho que na hora d escrever eu me perdi com o ),

mas tbm tem a ver com os nomes dos txtbox

Private Sub CommandButton1_Click()
    Dim L2 As Long, L As Long
    rang = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value2
    For L = 1 To UBound(rang, 1)
        If rang(L, 1) = TextBox1.Value Then
            L2 = L
        End If
    Next
    Cells(L2, 2).Value2 = Cells(L2, 2).Value2 + TextBox2.Value
    Cells(L2, 3).Value2 = Cells(L2, 3).Value2 + TextBox3.Value
End Sub

lembrando que os valores da celula e da txt tem que ser exatamente iguais

 
Postado : 28/07/2016 12:03 pm
(@edcronos2)
Posts: 0
New Member
 

olha , mas como falei, é apenas uma maneira muito simples de se fazer

nesse sai do loop depois que acha o valor

Private Sub CommandButton1_Click()
    Dim L As Long
    rang = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value2
    For L = 1 To UBound(rang, 1)
        If rang(L, 1) = TextBox1.Value Then
            Cells(L, 2).Value2 = Cells(L, 2).Value2 + TextBox2.Value
            Cells(L, 3).Value2 = Cells(L, 3).Value2 + TextBox3.Value
            Exit For
        End If
    Next
End Sub
 
Postado : 28/07/2016 12:13 pm
(@rafnakb)
Posts: 0
New Member
Topic starter
 

Sou novo aqui no fórum e as vezes fico perdido nas respostas.
Vou anexar um exemplo. Parece q não está indo por um detalhe q não consigo identificar.

Poderia dar uma olhada ?

 
Postado : 28/07/2016 12:23 pm
(@rafnakb)
Posts: 0
New Member
Topic starter
 

Funcionou exatamente como eu queria. Obrigado!!
O que preciso vou adaptando aqui a isso...

 
Postado : 28/07/2016 1:19 pm