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.
Por Mewertthon
#36951
Olá pessoal, estou aprendendo VBA e empaquei nesta macro e estou querendo saber de forma resumida o que ela faz. Em anexo eu coloquei a descrição da macro bem detalhada. Quem puder ajudar eu agradeço muito.

Sheets("Base").Select

Columns("M:AB").Select
Selection.Cut
Columns("CA:CA").Select
ActiveSheet.Paste
Columns("M:AB").Select
Selection.Delete Shift:=xlToLeft

Columns("BL:BL").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight

linha = 2
Do

celula1 = "BL" & linha
celula2 = "BM" & linha
celula3 = "BN" & linha
Range(celula1).Value = 1
Range(celula3).Value = 1
Range(celula2).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[14]<>"""",5,IF(RC[11]<>"""",4,IF(RC[8]<>"""",3,IF(RC[5]<>"""",2,IF(RC[2]<>"""",1,0)))))"

linha = linha + 1

If Sheets("Base").Cells(linha, 1).Value = "" Then
Exit Do
End If

Loop

M1 = linha - 1
M2 = (M1 - 1) + M1
M3 = (M1 - 1) + M2
M4 = (M1 - 1) + M3
M5 = (M1 - 1) + M4


Dados = "A2:BM" & M1
Range(Dados).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dados = "A" & M1 + 1
Range(Dados).Select
ActiveSheet.Paste

linha = M1 + 1
Do
celula3 = "BN" & linha
Range(celula3).Value = 2
linha = linha + 1
If linha = M2 + 1 Then
Exit Do
End If
Loop
Dados = "BR2:BT" & M1
Range(Dados).Select
Selection.Cut
Dados = "BO" & M1 + 1
Range(Dados).Select
ActiveSheet.Paste


Dados = "A2:BM" & M1
Range(Dados).Select
Selection.Copy
Dados = "A" & M2 + 1
Range(Dados).Select
ActiveSheet.Paste
linha = M2 + 1
Do
celula3 = "BN" & linha
Range(celula3).Value = 3
linha = linha + 1
If linha = M3 + 1 Then
Exit Do
End If
Loop
Dados = "BU2:BW" & M1
Range(Dados).Select
Selection.Cut
Dados = "BO" & M2 + 1
Range(Dados).Select
ActiveSheet.Paste


Dados = "A2:BM" & M1
Range(Dados).Select
Selection.Copy
Dados = "A" & M3 + 1
Range(Dados).Select
ActiveSheet.Paste
linha = M3 + 1
Do
celula3 = "BN" & linha
Range(celula3).Value = 4
linha = linha + 1
If linha = M4 + 1 Then
Exit Do
End If
Loop
Dados = "BX2:BZ" & M1
Range(Dados).Select
Selection.Cut
Dados = "BO" & M3 + 1
Range(Dados).Select
ActiveSheet.Paste

Dados = "A2:BM" & M1
Range(Dados).Select
Selection.Copy
Dados = "A" & M4 + 1
Range(Dados).Select
ActiveSheet.Paste
linha = M4 + 1
Do
celula3 = "BN" & linha
Range(celula3).Value = 5
linha = linha + 1
If linha = M5 + 1 Then
Exit Do
End If
Loop
Dados = "CA2:CC" & M1
Range(Dados).Select
Selection.Cut
Dados = "BO" & M4 + 1
Range(Dados).Select
ActiveSheet.Paste

Columns("BL:BL").Select
Selection.NumberFormat = "General"

linha = 2

Do
celula1 = "BL" & linha
Range(celula1).Select
ActiveCell.FormulaR1C1 = "=IF(RC[2]=1,IF(RC[3]<>"""",2,1),IF(RC[3]<>"""",1,0))"
linha = linha + 1
If Sheets("Base").Cells(linha, 1).Value = "" Then
Exit Do
End If
Loop

Columns("BO:BO").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

linha = 2

Do
celula1 = "BO" & linha
Range(celula1).Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]<>"""",IF(RC[2]<=2,1,0),0)"
linha = linha + 1
If Sheets("Base").Cells(linha, 1).Value = "" Then
Exit Do
End If
Loop

Columns("BP:BP").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

linha = 2

Do
celula1 = "BP" & linha
Range(celula1).Select
ActiveCell.FormulaR1C1 = "=IF(AND(RC[1]<>"""",RC[-63]=""Cancelado""),IF(RC[2]>2,1,0),0)"
linha = linha + 1
If Sheets("Base").Cells(linha, 1).Value = "" Then
Exit Do
End If
Loop

Sheets("Base Output").Select
Range("A2:BT50000").Select
Selection.ClearContents


Sheets("Base").Select

Columns("A:A").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select

linha = 2

Do
celula1 = "A" & linha
Range(celula1).Select
ActiveCell.FormulaR1C1 = "=MONTH(RC[16]) & "" "" &YEAR(RC[16])"
linha = linha + 1
If Sheets("Base").Cells(linha, 2).Value = "" Then
Exit Do
End If
Loop

celula1 = "A2:BT" & (linha - 1)
Range(celula1).Select
Selection.Copy
Sheets("Base Output").Select
Range("A2").Select
ActiveSheet.Paste


'Sheets("Dinamica").Select

'ActiveSheet.PivotTables("Tabela dinâmica1").PivotCache.Refresh

End Sub
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