gregurs Posted August 1, 2012 at 12:58 AM Report #471170 Posted August 1, 2012 at 12:58 AM Boa noite, tenho um formulário de fornecedores no qual consigo inserir na folha de excel o meu problema é que na folha de excel ele só me insere na mesma linha. o programa deve na folha de escel começar a inserir registos a partir da linha 12 o codigo que tenho é este: totalregistro = Worksheets("TABFORNECEDORES").UsedRange.Rows.Count + 1 With Worksheets("TABFORNECEDORES") .Cells(totalregistro, 2) = numerofornecedor .Cells(totalregistro, 3) = nome .Cells(totalregistro, 4) = contribuinte .Cells(totalregistro, 5) = endereço .Cells(totalregistro, 6) = contactofixo .Cells(totalregistro, 7) = contactomovel .Cells(totalregistro, 8) = email End With MsgBox "Gravado com sucesso"
acao Posted August 1, 2012 at 03:39 PM Report #471222 Posted August 1, 2012 at 03:39 PM boas muda o código para o evento change. ou fazer update à folha. tenta assim «Application.ScreenUpdating = True» ou fazeres um contador e sumares 1 à variavel «totalregisto» cumps acao
edsudani Posted August 3, 2012 at 03:10 PM Report #471395 Posted August 3, 2012 at 03:10 PM Boas gregurs Esperimente o seguinte procedimento num form à parte para ver se te serve. Private sub Cmd_Inserir() Dim TotalLinhas As Long Dim n1 As Variant 'Verifica quantas linhas tem a coluna. TotalLinhas = Range("A:A").Count 'No Range indicas a faixa a ser procurada. 'Varre a coluna "A" de baixo para cima. Range("A+Cstr(TotalLinhas)).End(xlUp).select 'Inserindo dados. n1 = InputBox"Entre com um Valor" 'Desloca-se para a próxima célula vasia ativando-a e transferindo o valor para ela. ActiveCell.Offset(1,0).Value = Cdbl(n1) End Sub Toda vez que premir o botão inserir, você acrescentará um valor na próxima célula. Veja se esta sugestão te ajuda. Edison
gregurs Posted August 24, 2012 at 09:27 PM Author Report #473445 Posted August 24, 2012 at 09:27 PM obrigado pela solução mas não consegui nada entre tanto consegui fazer isto mas o problema mantem-se pode ser que me detem algum problema no codigo linha = Worksheets("TABFORNECEDORES").UsedRange.Rows.Count + 1 For linha = 9 To 20 linha = linha + 1 With Worksheets("TABFORNECEDORES") .Cells(linha, 2) = numerofornecedor .Cells(linha, 3) = nome .Cells(linha, 4) = contribuinte .Cells(linha, 5) = endereço .Cells(linha, 6) = contactofixo .Cells(linha, 7) = contactomovel .Cells(linha, 8) = email End With linha = linha + 1 Exit For Next linha
zykon Posted August 28, 2012 at 11:43 AM Report #473782 Posted August 28, 2012 at 11:43 AM Eu uso o seguinte código para fazer algo semelhante e funciona bem. Private Sub AdicionarCliente_Click() Dim NewRow As Integer Dim ws As Worksheet Set ws = Worksheets("Tabelas Aux") NewRow = Worksheets("Tabelas Aux").Range("B" & Rows.Count).End(xlUp).Row + 1 If Trim(Me.TextBox1.Value) = "" Then Me.TextBox1.SetFocus MsgBox "Por favor introduza nome do cliente" Exit Sub End If 'copy the data to the database Worksheets("tabelas aux").Cells(NewRow, 2).Value = Addcliente.TextBox1.Value Me.TextBox1.Value = "" Addcliente.Hide End Sub
acao Posted September 27, 2012 at 10:50 AM Report #476753 Posted September 27, 2012 at 10:50 AM boas estive ausente só hoje tive oportunidade. linha = Worksheets("TABFORNECEDORES").UsedRange.Rows.Count + 1 isto acima não faz nada porque no contador «for» estás a dar o valor 9 á linha. For linha = 9 To 20 linha = linha + 1 With Worksheets("TABFORNECEDORES") .Cells(linha, 2) = numerofornecedor .Cells(linha, 3) = nome .Cells(linha, 4) = contribuinte .Cells(linha, 5) = endereço .Cells(linha, 6) = contactofixo .Cells(linha, 7) = contactomovel .Cells(linha, 8) = email End With linha = linha + 1 Exit For Next linha aqui o exit for é o teu problema termina o contador, elimina-o, e a instrução linha = linha + 1 estate a fazer andar o contador 2 linha em vez de 1, deves apagar as duas instruções, que o contador aumenta uma linha automaticamente. e como deste o valor 9 á linha vai começar na linha 9 teras que mudar para 12. cumps acao
jpaulino Posted October 1, 2012 at 06:32 AM Report #477267 Posted October 1, 2012 at 06:32 AM Vê este exemplo completo: Excel: Lista de Contactos - Parte I
acao Posted October 1, 2012 at 06:59 PM Report #477344 Posted October 1, 2012 at 06:59 PM Boa noite, tenho um formulário de fornecedores no qual consigo inserir na folha de excel o meu problema é que na folha de excel ele só me insere na mesma linha. o programa deve na folha de escel começar a inserir registos a partir da linha 12 o codigo que tenho é este: totalregistro = Worksheets("TABFORNECEDORES").UsedRange.Rows.Count + 1 With Worksheets("TABFORNECEDORES") .Cells(totalregistro, 2) = numerofornecedor .Cells(totalregistro, 3) = nome .Cells(totalregistro, 4) = contribuinte .Cells(totalregistro, 5) = endereço .Cells(totalregistro, 6) = contactofixo .Cells(totalregistro, 7) = contactomovel .Cells(totalregistro, 8) = email End With MsgBox "Gravado com sucesso" boas estive a testar o teu código, altera para totalregistro = Worksheets("TABFORNECEDORES").UsedRange.Rows.Count + 2 funciona em pleno. cumps acao
gregurs Posted October 7, 2012 at 07:07 PM Author Report #478157 Posted October 7, 2012 at 07:07 PM obrigado pessoal pela ajuda está a funcionar
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now