Estou reformulando alguns códigos do VBA que foram feitos 15 anos atrás e que alguém criou. Eu tenho que adicionar mais código para atender às nossas necessidades, mas eu excedi a quantidade de código permitido para ser executado.
Eu tenho um produto na coluna "AF" com os valores que preciso para combinar juntos na coluna "AH" "AL" e "AN" principalmente. O restante das colunas não precisa ser adicionado. Faça com que ele insira o intervalo de dados em uma parte diferente da planilha.
A primeira parte do Código Limpa os dados anteriores para que sejam limpos.
A segunda parte do código procura um Mosaico na Coluna AF e procura as linhas 41-60 pelo mesmo bloco depois de encontrar outro (ou se não o fizer) ele coloca em alguma linha na coluna A e em alguma linha no o intervalo 41-60. Isso se repete várias vezes até chegar a todas as linhas. Este funciona, mas uma vez que vai para 41-62 adicionando linhas adicionais, não funciona.
Private Sub FloorWallTileCombo_Click()
Dim TileSearch As String
Dim TotalPrice As Double, TotalSF As Double, TotalSurCap As Double, TotalCorCap As Double
'Dim TotalLF As Double, TotalAccentPcs As Double
For j = 41 To 60
ThisWorkbook.Worksheets("Breakdown").Cells(j, "A") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "D") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "E") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "F") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "H") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "I") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "J") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "K") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "O") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "P") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "Q") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(j, "R") = ""
ThisWorkbook.Worksheets("Breakdown").Cells(8, "B") = "Hand over the calculator, friends don’t let friends derive drunk."
ThisWorkbook.Worksheets("Breakdown").Cells(11, "B") = " "
'Application.ScreenUpdating = False
Next
TotalPrice = 0
TotalSF = 0
TotalSurCap = 0
TotalCorCap = 0
TileSearch = ThisWorkbook.Worksheets("Breakdown").Cells(41, "AF") 'starting Point from import
If TileSearch <> "" Then
For i = 41 To 60
If TileSearch = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AF") Then
'this line shouldnt change once number is in
'catch = i
ThisWorkbook.Worksheets("Breakdown").Cells(41, "O") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AB")
ThisWorkbook.Worksheets("Breakdown").Cells(41, "P") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AC")
ThisWorkbook.Worksheets("Breakdown").Cells(41, "Q") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AD")
ThisWorkbook.Worksheets("Breakdown").Cells(41, "A") = TileSearch
ThisWorkbook.Worksheets("Breakdown").Cells(41, "H") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AK")
ThisWorkbook.Worksheets("Breakdown").Cells(41, "J") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AM")
'need for price pulling
TotalPrice = TotalPrice + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AG")
TotalSF = TotalSF + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AH")
'this is for bullnose count
TotalSurCap = TotalSurCap + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AL")
TotalCorCap = TotalCorCap + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AQ")
ThisWorkbook.Worksheets("Breakdown").Cells(41, "D") = TotalPrice
ThisWorkbook.Worksheets("Breakdown").Cells(41, "I") = TotalSurCap
ThisWorkbook.Worksheets("Breakdown").Cells(41, "K") = TotalCorCap
ThisWorkbook.Worksheets("Breakdown").Cells(41, "R") = TotalSF
ThisWorkbook.Worksheets("Breakdown").Cells(41, "E") = ThisWorkbook.Worksheets("Breakdown").Cells(41, "V")
ThisWorkbook.Worksheets("Breakdown").Cells(41, "F") = ThisWorkbook.Worksheets("Breakdown").Cells(41, "U")
End If
Next i
End If
TotalPrice = 0
TotalSF = 0
TotalSurCap = 0
TotalCorCap = 0
TileSearch = ThisWorkbook.Worksheets("Breakdown").Cells(42, "AF")
If TileSearch <> "" And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(41, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(43, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(44, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(45, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(46, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(47, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(48, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(49, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(50, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(51, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(52, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(53, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(54, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(55, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(56, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(57, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(58, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(59, "A") _
And TileSearch <> ThisWorkbook.Worksheets("Breakdown").Cells(60, "A") Then
For i = 41 To 60
If TileSearch = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AF") Then
'this line shouldnt change once number is in
'catch = i
ThisWorkbook.Worksheets("Breakdown").Cells(42, "O") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AB")
ThisWorkbook.Worksheets("Breakdown").Cells(42, "P") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AC")
ThisWorkbook.Worksheets("Breakdown").Cells(42, "Q") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AD")
ThisWorkbook.Worksheets("Breakdown").Cells(42, "A") = TileSearch
ThisWorkbook.Worksheets("Breakdown").Cells(42, "H") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AK")
ThisWorkbook.Worksheets("Breakdown").Cells(42, "J") = ThisWorkbook.Worksheets("Breakdown").Cells(i, "AM")
'need for price pulling
TotalPrice = TotalPrice + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AG")
TotalSF = TotalSF + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AH")
'this is for bullnose count
TotalSurCap = TotalSurCap + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AL")
TotalCorCap = TotalCorCap + ThisWorkbook.Worksheets("Breakdown").Cells(i, "AQ")
ThisWorkbook.Worksheets("Breakdown").Cells(42, "D") = TotalPrice
ThisWorkbook.Worksheets("Breakdown").Cells(42, "I") = TotalSurCap
ThisWorkbook.Worksheets("Breakdown").Cells(42, "K") = TotalCorCap
ThisWorkbook.Worksheets("Breakdown").Cells(42, "R") = TotalSF
ThisWorkbook.Worksheets("Breakdown").Cells(42, "E") = ThisWorkbook.Worksheets("Breakdown").Cells(42, "V")
ThisWorkbook.Worksheets("Breakdown").Cells(42, "F") = ThisWorkbook.Worksheets("Breakdown").Cells(42, "U")
End If
Next i
End If
Editar: 3-23
Pergunta Respondida removida questão de erro de loop duplo.