Notifications
Clear all

NUMERAR LINHA SIM LINHA NÃO?

3 Posts
2 Usuários
0 Reactions
748 Visualizações
 Cpox
(@cpox)
Posts: 0
New Member
Topic starter
 

Boa noite pessoal,

Não sei se é pedir muito, mas estou com um problema que já está me deixando maluco, se alguém poder me ajudar agradeço.

Preciso numerar uma linha sim e outra não algo assim:

ID Curso Professor Inicio....
1 .............xxxxxx ..........xxxxxxxx .......xxxxx.....
OBS
2 ............xxxxxxx ..........xxxxxxx .........xxxxxxx.....
OBS
3 ...........xxxxxxxxx ........xxxxxxx ...........xxxxxxx...
OBS
....... e assim por diante.

o campo OBS já vai fica preenchido na planilha, preciso de um código para numerar dessa forma quando eu aperto o botão salvar,

estou usando isso, mas sempre quando salva a próxima linha sempre fica 1.

Por favor me ajudem.

Private Sub cmdSalvar_Click()

Worksheets(1).Range("A3").Select
 Do
    If Not (IsEmpty(ActiveCell)) Then
    ActiveCell.Offset(1, 0).Select
    
 End If
 
 Loop Until IsEmpty(ActiveCell) = True
 
 NumeraRegistro
    
 ActiveCell.Offset(0, 1).Value = ComboBoxCurso.Text
 ActiveCell.Offset(0, 2).Value = TextBoxInicio.Text
 ActiveCell.Offset(0, 3).Value = TextBoxTermino.Text
 ActiveCell.Offset(0, 4).Value = ComboBoxInstrutor.Text
 ActiveCell.Offset(0, 5).Value = ComboBoxfrequentantes.Text
 ActiveCell.Offset(0, 6).Value = ComboBoxPresentes.Text
 ActiveCell.Offset(0, 7).Value = ComboBoxEvasao.Text
 ActiveCell.Offset(0, 8).Value = ComboBoxTurno.Text
 ActiveCell.Offset(0, 9).Value = TextBoxData.Text
 ActiveCell.Offset(0, 10).Value = ComboBoxStatus.Text
 
Do

If (IsEmpty(ActiveCell)) Then
    ActiveCell.Offset(2, 0).Select
    
 End If
 
 Loop Until Not IsEmpty(ActiveCell) = True
 

 ActiveCell.Offset(2, 1).Value = TextBoxObs.Text
 
 LimparCampo
 
 ActiveWorkbook.Save

 MsgBox "Resgistro salvo com sucesso!", vbInformation, "Registro"
 
End Sub

Public Sub NumeraRegistro()

If IsNumeric(ActiveCell.Offset(-1, 0)) Then
   ActiveCell = ActiveCell(-1, 0) + 1
   
   Else
   
   ActiveCell = 1
   
End If

End Sub
 
Postado : 22/08/2016 4:41 pm
(@osvaldomp)
Posts: 857
Prominent Member
 

Experimente o código abaixo no lugar do seu.

Sub NumeraRegistro()
 If ActiveCell.Address = "$A$3" Then
  ActiveCell.Value = 1
 Else: ActiveCell.Value = ActiveCell.Offset(-2).Value + 1
 End If
End Sub
 
Postado : 22/08/2016 5:57 pm
 Cpox
(@cpox)
Posts: 0
New Member
Topic starter
 

Osvalado você é o cara!

Muito Obrigado, funcionou perfeitamente, agora vou poder continuar meu projeto, abrigado mesmo.

Vou aprender muito aqui no forum.

 
Postado : 23/08/2016 12:37 pm