Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
#21555
Preciso de alguma formar copiar os itens de uma planilha para a outra levando em consideração 3 condições diferentes.

O que fiz foi:
Código: Selecionar todos
Do While Not IsEmpty(Sheets("Base").Cells(linha, colunaTime))
            If Sheets("Base").Cells(linha, colunaProjeto).Value = ComboBoxProjeto.Value Then
                If CDate(Sheets("Base").Cells(linha, colunaAtualização).Value) = CDate(ComboBoxAtualização.Value) Then
                    If DatePart("h", CDate(Sheets("Base").Cells(linha, colunaTime).Value)) = DatePart("h", CDate(ComboBoxTime.Value)) Then
                        Sheets("Report").Range("M15").Value = Sheets("Base").Cells(linha, colunaDP).Value
                        Sheets("Report").Range("M10").Value = Sheets("Base").Cells(linha, colunaDR).Value
                        Sheets("Report").Range("Q15").Value = Sheets("Base").Cells(linha, colunaMdP).Value
                        Sheets("Report").Range("Q10").Value = Sheets("Base").Cells(linha, colunaMdR).Value
                        Sheets("Report").Range("U15").Value = Sheets("Base").Cells(linha, colunaAP).Value
                        Sheets("Report").Range("U10").Value = Sheets("Base").Cells(linha, colunaAR).Value
                        Sheets("Report").Range("Y15").Value = Sheets("Base").Cells(linha, colunaMP).Value
                        Sheets("Report").Range("Y10").Value = Sheets("Base").Cells(linha, colunaMR).Value
                        Sheets("Report").Range("AC15").Value = Sheets("Base").Cells(linha, colunaCP).Value
                        Sheets("Report").Range("AC10").Value = Sheets("Base").Cells(linha, colunaCR).Value
                        Sheets("Report").Range("C18").Value = Sheets("Base").Cells(linha, colunaObjetivo).Value
                        Sheets("Report").Range("Q18").Value = Sheets("Base").Cells(linha, colunaAtividadesRealizadas).Value
                        Sheets("Report").Range("C26").Value = Sheets("Base").Cells(linha, colunaProximasAtividades).Value
                        Sheets("Report").Range("Q26").Value = Sheets("Base").Cells(linha, colunaProblemasRiscosEncontrados).Value
                        Sheets("Report").Range("D6").Value = TextBoxID.Value
                        Sheets("Report").Range("F6").Value = ComboBoxProjeto.Value
                        Sheets("Report").Range("C5").Value = ComboBoxLider.Value
                    End If
                End If
            End If
            linha = linha + 1
        Loop
Porém está muito "pesado" o código e acaba travando o excel. Acham que tem algum outro jeito mais fácil de fazer?
#21580
Veja se ajuda.
Código: Selecionar todos
Do While Not IsEmpty(Sheets("Base").Cells(linha, colunaTime))
            If Sheets("Base").Cells(linha, colunaProjeto).Value = ComboBoxProjeto.Value Then
                If CDate(Sheets("Base").Cells(linha, colunaAtualização).Value) = CDate(ComboBoxAtualização.Value) Then
                    If DatePart("h", CDate(Sheets("Base").Cells(linha, colunaTime).Value)) = DatePart("h", CDate(ComboBoxTime.Value)) Then
                        Sheets("Report").Range("M15").Value = Sheets("Base").Cells(linha, colunaDP).Value
                        Sheets("Report").Range("M10").Value = Sheets("Base").Cells(linha, colunaDR).Value
                        Sheets("Report").Range("Q15").Value = Sheets("Base").Cells(linha, colunaMdP).Value
                        Sheets("Report").Range("Q10").Value = Sheets("Base").Cells(linha, colunaMdR).Value
                        Sheets("Report").Range("U15").Value = Sheets("Base").Cells(linha, colunaAP).Value
                        Sheets("Report").Range("U10").Value = Sheets("Base").Cells(linha, colunaAR).Value
                        Sheets("Report").Range("Y15").Value = Sheets("Base").Cells(linha, colunaMP).Value
                        Sheets("Report").Range("Y10").Value = Sheets("Base").Cells(linha, colunaMR).Value
                        Sheets("Report").Range("AC15").Value = Sheets("Base").Cells(linha, colunaCP).Value
                        Sheets("Report").Range("AC10").Value = Sheets("Base").Cells(linha, colunaCR).Value
                        Sheets("Report").Range("C18").Value = Sheets("Base").Cells(linha, colunaObjetivo).Value
                        Sheets("Report").Range("Q18").Value = Sheets("Base").Cells(linha, colunaAtividadesRealizadas).Value
                        Sheets("Report").Range("C26").Value = Sheets("Base").Cells(linha, colunaProximasAtividades).Value
                        Sheets("Report").Range("Q26").Value = Sheets("Base").Cells(linha, colunaProblemasRiscosEncontrados).Value
                        Sheets("Report").Range("D6").Value = TextBoxID.Value
                        Sheets("Report").Range("F6").Value = ComboBoxProjeto.Value
                        Sheets("Report").Range("C5").Value = ComboBoxLider.Value
			exit do
                    End If
                End If
            End If
            linha = linha + 1
        Loop
#21582
babdallas escreveu:Veja se ajuda.
Código: Selecionar todos
Do While Not IsEmpty(Sheets("Base").Cells(linha, colunaTime))
            If Sheets("Base").Cells(linha, colunaProjeto).Value = ComboBoxProjeto.Value Then
                If CDate(Sheets("Base").Cells(linha, colunaAtualização).Value) = CDate(ComboBoxAtualização.Value) Then
                    If DatePart("h", CDate(Sheets("Base").Cells(linha, colunaTime).Value)) = DatePart("h", CDate(ComboBoxTime.Value)) Then
                        Sheets("Report").Range("M15").Value = Sheets("Base").Cells(linha, colunaDP).Value
                        Sheets("Report").Range("M10").Value = Sheets("Base").Cells(linha, colunaDR).Value
                        Sheets("Report").Range("Q15").Value = Sheets("Base").Cells(linha, colunaMdP).Value
                        Sheets("Report").Range("Q10").Value = Sheets("Base").Cells(linha, colunaMdR).Value
                        Sheets("Report").Range("U15").Value = Sheets("Base").Cells(linha, colunaAP).Value
                        Sheets("Report").Range("U10").Value = Sheets("Base").Cells(linha, colunaAR).Value
                        Sheets("Report").Range("Y15").Value = Sheets("Base").Cells(linha, colunaMP).Value
                        Sheets("Report").Range("Y10").Value = Sheets("Base").Cells(linha, colunaMR).Value
                        Sheets("Report").Range("AC15").Value = Sheets("Base").Cells(linha, colunaCP).Value
                        Sheets("Report").Range("AC10").Value = Sheets("Base").Cells(linha, colunaCR).Value
                        Sheets("Report").Range("C18").Value = Sheets("Base").Cells(linha, colunaObjetivo).Value
                        Sheets("Report").Range("Q18").Value = Sheets("Base").Cells(linha, colunaAtividadesRealizadas).Value
                        Sheets("Report").Range("C26").Value = Sheets("Base").Cells(linha, colunaProximasAtividades).Value
                        Sheets("Report").Range("Q26").Value = Sheets("Base").Cells(linha, colunaProblemasRiscosEncontrados).Value
                        Sheets("Report").Range("D6").Value = TextBoxID.Value
                        Sheets("Report").Range("F6").Value = ComboBoxProjeto.Value
                        Sheets("Report").Range("C5").Value = ComboBoxLider.Value
			exit do
                    End If
                End If
            End If
            linha = linha + 1
        Loop
Caramba deu certo!!! Poderia me explicar exatamente o que faz o Exit Do?? Ele encerra o while assim que os três ifs são cumpridos?
#21585
Isso mesmo. Se as 3 condições foram atendidas, então faz as ações e depois sai do DO (usando exit do). Não tem necessidade de continuar nele.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord