Dim r As Range, arr() As Variant With Rows(3) Set r = .Find("Валюта для Розничной цены", , xlValues, xlWhole) arr = .FindNext(r).Offset(2).Resize(LastRow(.Cells), 2).Value r.Offset(2).Resize(UBound(arr), 2).Value = arr End With
Можно, если определиться, по какому критерию искать эту строку
[vba]
Код
Dim r As Range, arr() As Variant With Rows(3) Set r = .Find("Валюта для Розничной цены", , xlValues, xlWhole) arr = .FindNext(r).Offset(2).Resize(LastRow(.Cells), 2).Value r.Offset(2).Resize(UBound(arr), 2).Value = arr End With
Sub dd() Const dic$ = ":"="":<=<:>=>: =:"="":" Const pattern$ = "(?:<\/?(?:span|div|a|img|style|font|em|wbr|u)" & _ ".*?>(?:\s*\n\s*)*)|(?:(?:(<)([pb]r*|strong|t[abdhr]{1,2}" & _ "(?:le|ody)*|u*li*|h[0-9]*)\s.*?(?=\/*>))|(\S+))(?=[\s\S]*:" & _ "(?:\1|\3)=(:|.*?):)|(?:(\n)\s*)+" Dim arr() As Variant,i& With [Было!A1].CurrentRegion.Columns(3) If .Cells.Count < 2 Then Exit Sub arr = .Value For i = LBound(arr) + 1 To UBound(arr) arr(i, 1) = arr(i, 1) & dic With CreateObject("vbscript.regexp") .Global = True: .MultiLine = True .Pattern = pattern If .test(arr(i, 1)) Then arr(i, 1) = Replace(.Replace(arr(i, 1), "$4$2$5"), dic, "") End If End With Next .Value = arr End With End Sub
[/vba] [p.s.]Pattern и строка-"словарь" искаверканы сайтом, правильные в файле
Sub dd() Const dic$ = ":"="":<=<:>=>: =:"="":" Const pattern$ = "(?:<\/?(?:span|div|a|img|style|font|em|wbr|u)" & _ ".*?>(?:\s*\n\s*)*)|(?:(?:(<)([pb]r*|strong|t[abdhr]{1,2}" & _ "(?:le|ody)*|u*li*|h[0-9]*)\s.*?(?=\/*>))|(\S+))(?=[\s\S]*:" & _ "(?:\1|\3)=(:|.*?):)|(?:(\n)\s*)+" Dim arr() As Variant,i& With [Было!A1].CurrentRegion.Columns(3) If .Cells.Count < 2 Then Exit Sub arr = .Value For i = LBound(arr) + 1 To UBound(arr) arr(i, 1) = arr(i, 1) & dic With CreateObject("vbscript.regexp") .Global = True: .MultiLine = True .Pattern = pattern If .test(arr(i, 1)) Then arr(i, 1) = Replace(.Replace(arr(i, 1), "$4$2$5"), dic, "") End If End With Next .Value = arr End With End Sub
[/vba] [p.s.]Pattern и строка-"словарь" искаверканы сайтом, правильные в файле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
wolfire, excel автоматически резервирует отступы на физические поля принтера. Если принтер умеет печатать без полей, то нужно активировать соответствующий параметр в свойствах принтера. печать без полей в свойствах принтера отключена печать без полей в свойствах принтера включена
wolfire, excel автоматически резервирует отступы на физические поля принтера. Если принтер умеет печатать без полей, то нужно активировать соответствующий параметр в свойствах принтера. печать без полей в свойствах принтера отключена печать без полей в свойствах принтера включенаkrosav4ig
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
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
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