Notifications
Clear all

Problema Codigo Loop

2 Posts
2 Usuários
0 Reactions
734 Visualizações
(@victorsl)
Posts: 13
Eminent Member
Topic starter
 

Tenho Uma Planilha que ao inserir dados em um formulario e confirmar, ira chamar uma sub que verifica se o nome do Time digitado já existe em uma coluna, caso exista, o loop parte parte pro time b, caso nao tenha, deve inserir na ultima linha o time que não estiver na coluna, Meu codigo não esta funcionando não consigo entender

Sub InserirTimes(ByRef TimeA As String, ByRef TimeB As String)

lin = 3
col = 2
Linha = Sheets("NT").Range("B" & Rows.Count).End(xlUp).Row + 1
Do
If (Worksheets("NT").Cells(lin, col) = TimeA) Then
Exit Do
ElseIf (Worksheets("NT").Cells(lin, col) = "") Then
Sheets("NT").Cells(Linha, 2) = TimeA
Exit Do
Else
End If
lin = lin + 1
Loop While (lin < Linha)
'--------------
'--------------
lin = 3
col = 2
Linha = Sheets("NT").Range("B" & Rows.Count).End(xlUp).Row + 1
Do
If (Worksheets("NT").Cells(lin, col) = TimeB) Then
Exit Do
ElseIf (Worksheets("NT").Cells(lin, col) = "") Then
Sheets("NT").Cells(Linha, 2) = TimeB
Exit Do
Else
End If
lin = lin + 1
Loop While (lin < Linha)
End Sub

 
Postado : 16/09/2014 8:46 pm
(@gtsalikis)
Posts: 2373
Noble Member
 

Não testei, mas tente:

Sub InserirTimes(ByVal TimeA As String, ByVal TimeB As String)

lin = 3
col = 2
Linha = Sheets("NT").Range("B" & Rows.Count).End(xlUp).Row + 1
Do
If Worksheets("NT").Cells(lin, col).value2 = TimeA Then
Exit Do
ElseIf Worksheets("NT").Cells(lin, col).value2 = "" Then
Sheets("NT").Cells(Linha, 2).value2 = TimeA
Exit Do
Else
End If
lin = lin + 1
Loop While lin < Linha
'--------------
'--------------
lin = 3
col = 2
Linha = Sheets("NT").Range("B" & Rows.Count).End(xlUp).Row + 1
Do
If Worksheets("NT").Cells(lin, col).value2 = TimeB Then
Exit Do
ElseIf Worksheets("NT").Cells(lin, col).value2 = "" Then
Sheets("NT").Cells(Linha, 2).value2 = TimeB
Exit Do
Else
End If
lin = lin + 1
Loop While lin < Linha
End Sub

 
Postado : 17/09/2014 5:38 am