Sub Кнопка2_Щелчок() Dim c As Range With Application: .ScreenUpdating = 0: .EnableEvents = 0 With ActiveSheet.UsedRange .AutoFilter Field:=1, Criteria1:="214050000" .AutoFilter Field:=3, Criteria1:="3" .AutoFilter Field:=4, Criteria1:="91301" With .SpecialCells(12).Areas Set c = .Item(.Count).Rows(IIf(.Count > 1, 1, 2)) c.Cells(3) = 10 End With .AutoFilter Field:=3 .AutoFilter Field:=4 c.Rows.Hidden = True .Offset(1).SpecialCells(12).Rows.Delete xlUp .AutoFilter End With .ScreenUpdating = 1: .EnableEvents = 1: End With End Sub
[/vba]
Здравствуйте как-то так [vba]
Код
Sub Кнопка2_Щелчок() Dim c As Range With Application: .ScreenUpdating = 0: .EnableEvents = 0 With ActiveSheet.UsedRange .AutoFilter Field:=1, Criteria1:="214050000" .AutoFilter Field:=3, Criteria1:="3" .AutoFilter Field:=4, Criteria1:="91301" With .SpecialCells(12).Areas Set c = .Item(.Count).Rows(IIf(.Count > 1, 1, 2)) c.Cells(3) = 10 End With .AutoFilter Field:=3 .AutoFilter Field:=4 c.Rows.Hidden = True .Offset(1).SpecialCells(12).Rows.Delete xlUp .AutoFilter End With .ScreenUpdating = 1: .EnableEvents = 1: End With End Sub
Sub ConcatRows() Dim cell As Range, cell1 As Range, addr$ With Me.[B:B] Set cell = .Find("[expand", .Cells(1), xlFormulas, xlPart, xlByRows, xlNext, False, False) addr = cell.Address Do If InStr(cell, "[/expand") = 0 Then Set cell1 = .Find("[/expand", cell, xlFormulas, xlPart, xlByRows, xlNext, False, False) With Me.Range(cell, cell1) cell = Join(Application.Transpose(Me.Range(cell, cell1)), vbLf) .Offset(1).Resize(.Count - 1).Delete xlUp End With End If Set cell = .Find("[expand", cell, xlFormulas, xlPart, xlByRows, xlNext, False, False) Loop While Not cell Is Nothing And cell.Address <> addr End With End Sub
[/vba]
до кучи, вариант на VBA[vba]
Код
Sub ConcatRows() Dim cell As Range, cell1 As Range, addr$ With Me.[B:B] Set cell = .Find("[expand", .Cells(1), xlFormulas, xlPart, xlByRows, xlNext, False, False) addr = cell.Address Do If InStr(cell, "[/expand") = 0 Then Set cell1 = .Find("[/expand", cell, xlFormulas, xlPart, xlByRows, xlNext, False, False) With Me.Range(cell, cell1) cell = Join(Application.Transpose(Me.Range(cell, cell1)), vbLf) .Offset(1).Resize(.Count - 1).Delete xlUp End With End If Set cell = .Find("[expand", cell, xlFormulas, xlPart, xlByRows, xlNext, False, False) Loop While Not cell Is Nothing And cell.Address <> addr End With End Sub
Sub FormulaDvighenie() Names.Add Name:="FormulaDvighenieName", RefersTo:="=ТУТ ДЛИННАЯ ФОРМУЛА МАССИВА" Worksheets("Движение МЦ").Range("D11").Value = [FormulaDvighenieName] End Sub
[/vba]
Здравствуйте[vba]
Код
Sub FormulaDvighenie() Names.Add Name:="FormulaDvighenieName", RefersTo:="=ТУТ ДЛИННАЯ ФОРМУЛА МАССИВА" Worksheets("Движение МЦ").Range("D11").Value = [FormulaDvighenieName] End Sub
Mikael, не надо учить плохому не нужен тут select вместо [vba]
Код
Range("a5:a" & LastRow([a1])).Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _ "=СЖПРОБЕЛЫ(A5)<>A5" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 255 .TintAndShade = 0 End With ' Первый столбик / Красное / Проверка УФ на дубликаты названий Selection.FormatConditions.AddUniqueValues Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority Selection.FormatConditions(1).DupeUnique = xlDuplicate With Selection.FormatConditions(1).Font .Color = -16383844 .TintAndShade = 0 End With With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 13551615 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False
[/vba] пишем [vba]
Код
With Range("a5:a" & LastRow([a1])).FormatConditions With .Add(xlExpression, Formula1:="=СЖПРОБЕЛЫ(RC)<>RC") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 255 .TintAndShade = 0 End With End With ' Первый столбик / Красное / Проверка УФ на дубликаты названий With .AddUniqueValues .SetFirstPriority .DupeUnique = xlDuplicate With .Font .Color = -16383844 .TintAndShade = 0 End With With .Interior .PatternColorIndex = xlAutomatic .Color = 13551615 .TintAndShade = 0 End With .StopIfTrue = False End With End With
[/vba]
Вместо[vba]
Код
Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With ' Формула 3-2 / Зеленый / В корзину (в наличии) (цена ДА / остаток ДА / разрешить покупку НЕТ) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5>0;H5:H5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With ' Формула 3-1 / Зеленый / Запросить цену (в наличии) цена НЕТ / остаток ДА / разрешить покупку ДА Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5<=0;G5:G5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With
' Формула 2-2 / Желтое / В корзину (под заказ) (цена ДА/ остаток НЕТ / разрешить покупку ДА) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>=0;G5:G5<=0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With ' Формула 2-1 / Желтое / Запросить цену (под заказ) (цена НЕТ / остаток НЕТ / разрешить покупку ДА) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5<=0;G5:G5<=0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With
' Формула 1-2 / Красный цвет / Подписаться (цена ДА / остаток НЕТ / разрешить покупку НЕТ) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5<=0;H5:H5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With ' Формула 1-1 / Красный цвет / Запросить цену (не доступно) (цена ДА / остаток НЕТ / разрешить покупку НЕТ) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5<=0;H5:H5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With
[/vba] пишем [vba]
Код
With Range("h5:h" & LastRow([h1])).FormatConditions With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 3-2 / Зеленый / В корзину (в наличии) (цена ДА / остаток ДА / разрешить покупку НЕТ) With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7>0;RC>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 3-1 / Зеленый / Запросить цену (в наличии) цена НЕТ / остаток ДА / разрешить покупку ДА With .Add(xlExpression, Formula1:="=И(R[]C6<=0;R[]C7>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 2-2 / Желтое / В корзину (под заказ) (цена ДА/ остаток НЕТ / разрешить покупку ДА) With .Add(xlExpression, Formula1:="=И(R[]C6>=0;R[]C7<=0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With .StopIfTrue = False End With ' Формула 2-1 / Желтое / Запросить цену (под заказ) (цена НЕТ / остаток НЕТ / разрешить покупку ДА) With .Add(xlExpression, Formula1:="=И(R[]C6<=0;R[]C7<=0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With .StopIfTrue = False End With ' Формула 1-2 / Красный цвет / Подписаться (цена ДА / остаток НЕТ / разрешить покупку НЕТ) With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7<=0;RC>0)") .SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 1-1 / Красный цвет / Запросить цену (не доступно) (цена ДА / остаток НЕТ / разрешить покупку НЕТ) With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7<=0;RC>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With End With
[/vba] и т.д. по аналогии [p.s.]при таком подходе необходимо использовать R1C1 адресацию в формулах
Mikael, не надо учить плохому не нужен тут select вместо [vba]
Код
Range("a5:a" & LastRow([a1])).Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _ "=СЖПРОБЕЛЫ(A5)<>A5" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 255 .TintAndShade = 0 End With ' Первый столбик / Красное / Проверка УФ на дубликаты названий Selection.FormatConditions.AddUniqueValues Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority Selection.FormatConditions(1).DupeUnique = xlDuplicate With Selection.FormatConditions(1).Font .Color = -16383844 .TintAndShade = 0 End With With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 13551615 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False
[/vba] пишем [vba]
Код
With Range("a5:a" & LastRow([a1])).FormatConditions With .Add(xlExpression, Formula1:="=СЖПРОБЕЛЫ(RC)<>RC") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 255 .TintAndShade = 0 End With End With ' Первый столбик / Красное / Проверка УФ на дубликаты названий With .AddUniqueValues .SetFirstPriority .DupeUnique = xlDuplicate With .Font .Color = -16383844 .TintAndShade = 0 End With With .Interior .PatternColorIndex = xlAutomatic .Color = 13551615 .TintAndShade = 0 End With .StopIfTrue = False End With End With
[/vba]
Вместо[vba]
Код
Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With ' Формула 3-2 / Зеленый / В корзину (в наличии) (цена ДА / остаток ДА / разрешить покупку НЕТ) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5>0;H5:H5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With ' Формула 3-1 / Зеленый / Запросить цену (в наличии) цена НЕТ / остаток ДА / разрешить покупку ДА Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5<=0;G5:G5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With
' Формула 2-2 / Желтое / В корзину (под заказ) (цена ДА/ остаток НЕТ / разрешить покупку ДА) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>=0;G5:G5<=0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With ' Формула 2-1 / Желтое / Запросить цену (под заказ) (цена НЕТ / остаток НЕТ / разрешить покупку ДА) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5<=0;G5:G5<=0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With
' Формула 1-2 / Красный цвет / Подписаться (цена ДА / остаток НЕТ / разрешить покупку НЕТ) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5<=0;H5:H5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With ' Формула 1-1 / Красный цвет / Запросить цену (не доступно) (цена ДА / остаток НЕТ / разрешить покупку НЕТ) Selection.FormatConditions(1).StopIfTrue = False Range("H5:H1100").Select 'Columns("H:H").Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=И(F5:F5>0;G5:G5<=0;H5:H5>0)" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With
[/vba] пишем [vba]
Код
With Range("h5:h" & LastRow([h1])).FormatConditions With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 3-2 / Зеленый / В корзину (в наличии) (цена ДА / остаток ДА / разрешить покупку НЕТ) With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7>0;RC>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 3-1 / Зеленый / Запросить цену (в наличии) цена НЕТ / остаток ДА / разрешить покупку ДА With .Add(xlExpression, Formula1:="=И(R[]C6<=0;R[]C7>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent3 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 2-2 / Желтое / В корзину (под заказ) (цена ДА/ остаток НЕТ / разрешить покупку ДА) With .Add(xlExpression, Formula1:="=И(R[]C6>=0;R[]C7<=0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With .StopIfTrue = False End With ' Формула 2-1 / Желтое / Запросить цену (под заказ) (цена НЕТ / остаток НЕТ / разрешить покупку ДА) With .Add(xlExpression, Formula1:="=И(R[]C6<=0;R[]C7<=0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .Color = 10079487 .TintAndShade = 0 .PatternTintAndShade = 0 End With .StopIfTrue = False End With ' Формула 1-2 / Красный цвет / Подписаться (цена ДА / остаток НЕТ / разрешить покупку НЕТ) With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7<=0;RC>0)") .SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With ' Формула 1-1 / Красный цвет / Запросить цену (не доступно) (цена ДА / остаток НЕТ / разрешить покупку НЕТ) With .Add(xlExpression, Formula1:="=И(R[]C6>0;R[]C7<=0;RC>0)") .SetFirstPriority With .Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.599963377788629 End With .StopIfTrue = False End With End With
[/vba] и т.д. по аналогии [p.s.]при таком подходе необходимо использовать R1C1 адресацию в формулахkrosav4ig
wolfire, excel автоматически резервирует отступы на физические поля принтера. Если принтер умеет печатать без полей, то нужно активировать соответствующий параметр в свойствах принтера. печать без полей в свойствах принтера отключена печать без полей в свойствах принтера включена
wolfire, excel автоматически резервирует отступы на физические поля принтера. Если принтер умеет печатать без полей, то нужно активировать соответствующий параметр в свойствах принтера. печать без полей в свойствах принтера отключена печать без полей в свойствах принтера включенаkrosav4ig
Sub УФ_стереть_создать() ' ////////////////////////////////// ' Вставка Y в параметр НДС включен в цену? On Error Resume Next With Rows(3).Find("НДС включен в цену ?", , xlValues, xlWhole).Offset(2) Range(.Cells, Cells(Rows.Count, .Column)).SpecialCells(xlCellTypeBlanks) = "Y" End With ' ////////////////////////////////// MsgBox "ВСЕ!" End Sub
[/vba]
как-то так [vba]
Код
Sub УФ_стереть_создать() ' ////////////////////////////////// ' Вставка Y в параметр НДС включен в цену? On Error Resume Next With Rows(3).Find("НДС включен в цену ?", , xlValues, xlWhole).Offset(2) Range(.Cells, Cells(Rows.Count, .Column)).SpecialCells(xlCellTypeBlanks) = "Y" End With ' ////////////////////////////////// MsgBox "ВСЕ!" End Sub