Я обновляю код VBA, созданный 15 лет назад и созданный кем-то другим. Я должен добавить больше кода, чтобы удовлетворить наши потребности, но я превышаю количество кода, разрешенного для запуска.
У меня есть Продукты в столбце "AF" со значениями, которые необходимо объединить в основном в столбцах "AH", "AL" и "AN". Остальные столбцы добавлять не нужно. Пусть он введет диапазон данных в другой части рабочего листа.
Первая часть Кодекса очищает предыдущие данные, поэтому они чистые.
Вторая часть кода ищет плитку в столбце AF и ищет строки 41-60 для той же плитки, как только находит другую (или, если нет), вставляет некоторую строку в столбце A и некоторую строку в 41- 60 ассортимент. Это повторяется снова и снова, пока не пройдет все строки. Этот работает, но как только он идет к 41-62, добавляя дополнительные строки, он не работает.
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
Изменить: 3-23 Вопрос Ответ удален вопрос об ошибке двойной петли.