matoso Posted May 17, 2012 at 04:42 PM Report #456460 Posted May 17, 2012 at 04:42 PM Pessoal tem a seguinte macro para copiar o texto da célula acima, só que está demorando muito e ele completa até o final, gostaria que ele completasse até onde tem texto na coluna ao lado. alguém pode me ajudar? ex arquivo: .........A............. .........B.......... .........C......... ...D........ ...E........ ...F.. PRODUTO:......... C96314421........ ITEM1 22120................ =ACIMA......... =ACIMA........ OPER1...... 0,00728..... 8 22320................ =ACIMA......... =ACIMA........ OPER2...... 0,00575..... 1 24500................ =ACIMA......... =ACIMA........ OPER3...... 0,00583..... 1 PRODUTO: ......... C97314421........ ITEM2 22120................ =ACIMA......... =ACIMA........ OPER4...... 0,00784..... 8 22320................ =ACIMA......... =ACIMA........ OPER4...... 0,00784..... 8 24500................ =ACIMA......... =ACIMA........ OPER4...... 0,00784..... 8 PRODUTO: ......... C98314421........ ITEM3 22120................ =ACIMA......... =ACIMA........ OPER4...... 0,00784..... 8 22320................ =ACIMA......... =ACIMA........ OPER4...... 0,00784..... 8 22320................ =ACIMA......... =ACIMA........ OPER4...... 0,00784..... 8 .........................AQUI TEM QUE PARAR Sub copia() Columns("B:B").Select For i = 1 To Selection.Cells.Count - 1 j = i + 1 If Selection.Cells(j, 1).Value = "" Then Selection.Cells(j, 1).Value = Selection.Cells(i, 1).Value End If Next i End Sub
matoso Posted May 24, 2012 at 02:10 PM Author Report #457859 Posted May 24, 2012 at 02:10 PM Alguém para ajudar?????????
FreiNando Posted May 24, 2012 at 09:18 PM Report #457988 Posted May 24, 2012 at 09:18 PM (edited) A causa de demorar muito tempo é fazeres a macro correr para todas as células da coluna. Até ao Excel 2003 eram 65535. A partir do Excel 2007 são 1 048 576 !!!! Podes obter a linha da ultima célula da coluna C usando Range("C:C").End(xlDown).Row Fica a macro completa: Private Sub CopiarAcima() Dim Rg As Range, I As Long Set Rg = Range("B1") For I = 0 To Range("C:C").End(xlDown).Row - 1 If Rg.Offset(I, 0).Value = "" Then Rg.Offset(I + 1, 0).Value = Rg.Offset(I, 0).Value End If Next I End Sub Edited May 24, 2012 at 09:20 PM by FreiNando O caminho mais curto para conseguir fazer muitas coisas é fazer uma de cada vez. Samuel Smiles
matoso Posted May 28, 2012 at 10:49 AM Author Report #458480 Posted May 28, 2012 at 10:49 AM Ok Obrigado pelo retorno. Talvez, eu não soube colocar o comando, eu já tenho uma macro e gostaria de inserir essa para continuar a execução, como essa inicia com sub private, o comando entende que é uma nova macro e daí não vai. Eu quero que a base seja a coluna A, que pare quando não tiver mais nada nessa coluna e copie os dados da célula B e C. Se puder me ajudar agradeço. Pois o arquivo tem mais de 300.000 linhas. obrigado.
FreiNando Posted May 28, 2012 at 10:22 PM Report #458717 Posted May 28, 2012 at 10:22 PM Não entendi! Não consegues mudar de private para public, nem trocar a coluna de referência? Pressiona F1 quando tiveres dúvidas sobre um comando. O caminho mais curto para conseguir fazer muitas coisas é fazer uma de cada vez. Samuel Smiles
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