Sub Botão1_Clique()
Dim vazia As Range, número_da_linha As Integer
Application.ScreenUpdating = False
'This makes you unable to see what is happening. It speeds up the process by allowing your computer to run the program without displaying anything.
número_da_linha = 4
This sets the variable equal to 4. You need the "_" to keep all of the words together and considered as one whole word, not 3 individual ones.
For Each vazia In Range("B4:B3000")
'This basically says "look for each range(also considered a cell) within the area 'B4:B3000'"
If vazia.FormulaR1C1 = "" Then Range(Range("B" & número_da_linha) _
, Range("B" & número_da_linha).Offset(, 9)).ClearContents
'This is one line of code, separated into two lines (so that you can read all of it without scrolling) by the "_". To better understand this method, search the internet.
'This code says "if the current cell's formula is blank or empty, then clear the contents of the range 'B?' to 'K?'" and the '?' is whichever number 'número_da_linha' is equal to.
número_da_linha = número_da_linha + 1
'This raises número_da_linha from 4 to 5, 5 to 6, and so on. it is how the program clears all of the lines, but it does so one line at a time. this is why i used "Application.ScreenUpdating = False"
Next vazia
'This pushes the path of the code back to the line "For Each vazia in Range...". It allows the code to go to cell "B?" and continue the trend until cell "B3000"
número_da_linha = 4
For Each vazia In Range("D4:D3000")
If vazia.FormulaR1C1 = "" Then Range(Range("D" & número_da_linha).Offset(, -2) _
, Range("D" & número_da_linha).Offset(, 7)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("E4:E3000")
If vazia.FormulaR1C1 = "" Then Range(Range("E" & número_da_linha).Offset(, -3) _
, Range("E" & número_da_linha).Offset(, 6)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("F4:F3000")
If vazia.FormulaR1C1 = "" Then Range(Range("F" & número_da_linha).Offset(, -4) _
, Range("F" & número_da_linha).Offset(, 5)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("G4:G3000")
If vazia.FormulaR1C1 = "" Then Range(Range("G" & número_da_linha).Offset(, -5) _
, Range("G" & número_da_linha).Offset(, 4)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("H4:H3000")
If vazia.FormulaR1C1 = "" Then Range(Range("H" & número_da_linha).Offset(, -6) _
, Range("H" & número_da_linha).Offset(, 3)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("I4:I3000")
If vazia.FormulaR1C1 = "" Then Range(Range("I" & número_da_linha).Offset(, -7) _
, Range("I" & número_da_linha).Offset(, 2)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("J4:J3000")
If vazia.FormulaR1C1 = "" Then Range(Range("J" & número_da_linha).Offset(, -8) _
, Range("J" & número_da_linha).Offset(, 1)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
número_da_linha = 4
For Each vazia In Range("K4:K3000")
If vazia.FormulaR1C1 = "" Then Range(Range("K" & número_da_linha).Offset(, -9) _
, Range("K" & número_da_linha)).ClearContents
número_da_linha = número_da_linha + 1
Next vazia
Range("C4").FormulaR1C1 = "=IF(RC[-1]=1, ""Cablena VW"", IF(RC[-1]=2, ""Cablena YH"", IF(RC[-1]=3, ""Capri"", IF(RC[-1]=4, ""Sakaguchi Industrial"", IF(RC[-1]=5, ""Metalurgica Sakaguchi"", IF(RC[-1]=6, ""Winflex"", IF(RC[-1]=7, ""Littelfuse"",IF(RC[-1]=8, ""Loopmol"", IF(RC[-1]=9, ""ITW"", IF(RC[-1]=10, ""Newtoy"", IF(RC[-1]=11, ""Kluber"")))))))))))"
'This sets the value of "C4" equal to your original formula. The "RC[-1]" refers to "one column to the left of the current cell". R = rows, C = columns. If i have R[-4]C[7] that refers to "4 rows above and 7 columns to the right of the current cell"
Range("C4").Select
'selects "C4"
Selection.AutoFill Destination:=Range("C4:C" & número_da_linha), Type:=xlFillDefault
'Makes all cells in column C have the same formula and format as "C4"
Application.ScreenUpdating = True
'lets you see whats happening again
End Sub
Bookmarks