Notifications
Clear all

Comando iLastRow (Em uma coluna especifica)

3 Posts
2 Usuários
0 Reactions
959 Visualizações
(@kassioak)
Posts: 5
Active Member
Topic starter
 

Boa tarde Srs

Sou iniciante em excel VB e estou com dúvida na seguinte situação:

[quote]Private Sub cmd_Gravar_Click()
Dim iLastRow As Integer

    iLastRow = ActiveSheet.UsedRange.Rows.Count 'Conta o número de linhas preenchidas no arquivo
    
    iLastRow = iLastRow + 1 'valor de iLastRow será a próxima célula (que estará vazia)

'Preencher as células vazias com os valores das TextBoxes:
'-----------
    Range("A" & iLastRow).Value = txt_NoRegistro.Text
    Range("C" & iLastRow).Value = txt_Cliente.Text
    Range("D" & iLastRow).Value = txt_Dia.Text
    Range("E" & iLastRow).Value = txt_Ref.Text
    Range("H" & iLastRow).Value = txt_Responsavel.Text
    Range("I" & iLastRow).Value = txt_Control1.Text
    Range("J" & iLastRow).Value = txt_Control2.Text
'-----------

    ActiveWorkbook.Save 'Salva a pasta de trabalho
End Sub[/quote]

Na linha " iLastRow = ActiveSheet.UsedRange.Rows.Count", como posso indicar a coluna e planilha? Pois no meu caso, preciso seja preenchida a ultima linha vazia, mas contando de uma determinada coluna (B) em uma planilha especifica(DADOS).

Agradeço desde já pelas explanações

 
Postado : 02/06/2014 11:29 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Uma maneira:
iLastRow=Cells(Cells.Rows.Count, 1).End(xlUp).Row ou iLastRow=Cells(Cells.Rows.Count, "A").End(xlUp).Row
ou determinando a planilha
ilastRow=sheets("DADOS").Cells(Cells.Rows.Count, 1).End(xlUp).Row ou ilastRow=sheets("DADOS").Cells(Cells.Rows.Count, "A").End(xlUp).Row

Pode utilizar o numero da coluna (1) ou a letra ("A") que a representa. substitua pela coluna desejada

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 02/06/2014 12:40 pm
(@kassioak)
Posts: 5
Active Member
Topic starter
 

Deu certinho.
Muito Obrigado.
A quem procurar por duvida semelhante, lembre-se que o comando não funcionará corretamente se a mesma estiver formatada como tabela

 
Postado : 02/06/2014 1:26 pm