PDA

View Full Version : Solved: Insert new data in first row



ioncila
12-04-2009, 08:52 AM
Hi
I dont know if this is possible.

I have this workbook which is a small database. This wbk has a userform that inputs new data in a sheet i call "movements".
So everytime i fill the userform and click save button, that inputs new register in a new row.

What I'm asking is it's possible the new row (the newer register) be always in row 2 and the previous one goes to row 3 and so on?

Thank You in advance

Bob Phillips
12-04-2009, 09:03 AM
Rows(2).Insert
'now add data to row 2

ioncila
12-04-2009, 09:55 AM
Thank you for reply. But it seems something is not right.

An error returns "Compile Method or Data Member Not Found" in bold line:

Private Sub btnOK_Click()
Dim proximoId As Long
'Altera
If optAlterar.Value Then
Call SalvaRegistro(CLng(txtCOD.Text), indiceRegistro)
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Novo
If optNovo.Value Then
proximoId = PegaProximoId
'pega a próxima linha
Dim proximoIndice As Long
proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
Call SalvaRegistro(proximoId, proximoIndice)
txtCOD = proximoId
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Excluir
If optExcluir.Value Then
Dim result As VbMsgBoxResult
result = MsgBox("Deseja excluir o registro nº " & txtCOD.Text & " ?", vbYesNo, "Confirmação")

If result = vbYes Then
wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colCOD), wsCadastro.Cells(indiceRegistro, colCOD)).EntireRow.Delete
Call CarregaDadosInicial
lblMensagem.Caption = "Registro excluído com sucesso"
End If
End If

Call HabilitaBotoesAlteracao
Call DesabilitaControles

Dim strGrupo As String
Dim ws As Worksheet

'Registar em "Movimentos"

Set ws = Worksheets("Movimentos")

ws.Row(2).Insert

If txtENTRADAS.Value > 0 Then
strGrupo = "Entrada"
ws.Cells(2, 15).Value = txtENTRADAS.Value
ElseIf txtSIADAS.Value > 0 Then
strGrupo = "Saída"
ws.Cells(2, 15).Value = txtSAIDAS.Value
End If

With ws
.Cells(2, 1).Value = strGrupo
.Cells(2, 2).Value = txtDATA.Text
.Cells(2, 1).Value = txtORIGEM.Text
.Cells(2, 1).Value = txtDESTINO.Text
.Cells(2, 1).Value = txtRESPONSAVEL.Text
.Cells(2, 1).Value = txtNOME.Text
.Cells(2, 1).Value = txtTIPO.Text
.Cells(2, 1).Value = txtMATERIAL.Text
.Cells(2, 1).Value = txtMARCA.Text
.Cells(2, 1).Value = txtMODELO.Text
.Cells(2, 1).Value = txtDN1.Text
.Cells(2, 1).Value = txtDN2.Text
.Cells(2, 1).Value = txtPN.Text
.Cells(2, 1).Value = txtOBS.Text
.Cells(2, 1).Value = txtPRECOUNIT.Value
.Cells(2, 1).Value = txtVALORTOTAL.Value
End With

End Sub

What is wrong?

lucas
12-04-2009, 09:58 AM
rows I think you left off the S

ioncila
12-04-2009, 10:32 AM
rows I think you left off the S

Yes. It was that. Thanks.

Bob Phillips
12-04-2009, 11:20 AM
Glad to see my help desk is always online :)

lucas
12-04-2009, 11:31 AM
chuckle, I made that same mistake once so I recognized it immediately.......