Sub d() Dim arr() As Variant Dim r As Range Set r = Parent.Sheets("Лист1").UsedRange With Me.UsedRange.Columns("B:E") arr = .Value For i = 1 To UBound(arr) For j = 2 To UBound(arr, 2) Step 2 With Application arr(i, j) = .IfError(.VLookup(arr(i, j - 1), r, 3, 0), "") End With Next Next .Value = arr End With End Sub
[/vba] до кучи в обратную сторону [vba]
Код
Sub d() Dim arr() As Variant Dim rng As Range Set rng = Parent.Sheets("Лист2").UsedRange With Me.UsedRange.Columns("A:C") arr = .Value For i = 1 To UBound(arr) Set r = rng.Find(arr(i, 1), , xlValues, xlWhole, , , False, , False) If Not r Is Nothing Then arr(i, 3) = r.Offset(, 1).Value Next .Value = arr End With End Sub
Sub d() Dim arr() As Variant Dim r As Range Set r = Parent.Sheets("Лист1").UsedRange With Me.UsedRange.Columns("B:E") arr = .Value For i = 1 To UBound(arr) For j = 2 To UBound(arr, 2) Step 2 With Application arr(i, j) = .IfError(.VLookup(arr(i, j - 1), r, 3, 0), "") End With Next Next .Value = arr End With End Sub
[/vba] до кучи в обратную сторону [vba]
Код
Sub d() Dim arr() As Variant Dim rng As Range Set rng = Parent.Sheets("Лист2").UsedRange With Me.UsedRange.Columns("A:C") arr = .Value For i = 1 To UBound(arr) Set r = rng.Find(arr(i, 1), , xlValues, xlWhole, , , False, , False) If Not r Is Nothing Then arr(i, 3) = r.Offset(, 1).Value Next .Value = arr End With End Sub
let Источник = Excel.CurrentWorkbook(){[Name="Таблица1"]}[Content], #"Измененный тип" = Table.TransformColumnTypes(Источник,{{"время", type datetime}, {"Код", Int64.Type}, {"Цвет", type text}, {"Имя", type text}}), #"Сгруппированные строки" = Table.Group(#"Измененный тип", {"время", "Код"}, {{"Цвет", each Text.Combine(List.Distinct([Цвет]),",")},{"Имя",each Text.Combine(List.Distinct([Имя]),",")}}) in #"Сгруппированные строки"
[/vba]
вариант через PowerQuery [vba]
Код
let Источник = Excel.CurrentWorkbook(){[Name="Таблица1"]}[Content], #"Измененный тип" = Table.TransformColumnTypes(Источник,{{"время", type datetime}, {"Код", Int64.Type}, {"Цвет", type text}, {"Имя", type text}}), #"Сгруппированные строки" = Table.Group(#"Измененный тип", {"время", "Код"}, {{"Цвет", each Text.Combine(List.Distinct([Цвет]),",")},{"Имя",each Text.Combine(List.Distinct([Имя]),",")}}) in #"Сгруппированные строки"
Private Sub Worksheet_Change(ByVal Target As Range) Dim vVal, oRE As Object
On Local Error Resume Next If Intersect(Target, Range("D9")) Is Nothing Then Exit Sub Application.EnableEvents = 0 With Target Set re = CreateObject("vbscript.regexp") re.Pattern = "^([0-1][0-9]|2[0-3])[0-5][0-9]$" vVal = Format(.Value, "0000") If re.test(vVal) Then .Value = Application.Replace(vVal, 3, 0, ":") .NumberFormat = "h:mm" Else MsgBox "Введенные данные не соответствуют времени в формате ччмм" Application.Undo End If End With Application.EnableEvents = True Set re = Nothing End Sub
[/vba]
Здравствуйте. [vba]
Код
Private Sub Worksheet_Change(ByVal Target As Range) Dim vVal, oRE As Object
On Local Error Resume Next If Intersect(Target, Range("D9")) Is Nothing Then Exit Sub Application.EnableEvents = 0 With Target Set re = CreateObject("vbscript.regexp") re.Pattern = "^([0-1][0-9]|2[0-3])[0-5][0-9]$" vVal = Format(.Value, "0000") If re.test(vVal) Then .Value = Application.Replace(vVal, 3, 0, ":") .NumberFormat = "h:mm" Else MsgBox "Введенные данные не соответствуют времени в формате ччмм" Application.Undo End If End With Application.EnableEvents = True Set re = Nothing End Sub
Sub PlaceColon() With Me.UsedRange.Columns("A") .Value = Application.Replace(.Value, 7, 0, ",") .Replace ",,", ",", xlPart, , , , False, False .Replace ",", "", xlWhole, , , , False, False With Selection .Find "", .Cells, xlFormulas, 2, 1, 1, 0, 0 End With End With End Sub
[/vba]
до кучи макрос [vba]
Код
Sub PlaceColon() With Me.UsedRange.Columns("A") .Value = Application.Replace(.Value, 7, 0, ",") .Replace ",,", ",", xlPart, , , , False, False .Replace ",", "", xlWhole, , , , False, False With Selection .Find "", .Cells, xlFormulas, 2, 1, 1, 0, 0 End With End With End Sub
Sub Макрос1() Dim shps As Shapes, shp As Shape Dim i As Long, x1, x2, y1, y2 Set shps = ActiveSheet.Shapes Set shp = ActiveSheet.Shapes([k3]) x2 = shp.Left + shp.Width / 2 y2 = shp.Top + shp.Height / 2 For i = 1 To shps.Count With shps(i) If Not (Intersect(.TopLeftCell, [B4:S45]) Is Nothing Or Intersect(.BottomRightCell, [B4:S45]) Is Nothing) Then x1 = .Left + .Width / 2 y1 = .Top + .Height / 2 .Fill.Transparency = -(((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5 > 100) .Line.Transparency = .Fill.Transparency If .Type = msoPicture Then .Visible = .Fill.Transparency = 0 End If End With Next i End Sub
[/vba]
Здравствуйте. как-то так, наверное [vba]
Код
Sub Макрос1() Dim shps As Shapes, shp As Shape Dim i As Long, x1, x2, y1, y2 Set shps = ActiveSheet.Shapes Set shp = ActiveSheet.Shapes([k3]) x2 = shp.Left + shp.Width / 2 y2 = shp.Top + shp.Height / 2 For i = 1 To shps.Count With shps(i) If Not (Intersect(.TopLeftCell, [B4:S45]) Is Nothing Or Intersect(.BottomRightCell, [B4:S45]) Is Nothing) Then x1 = .Left + .Width / 2 y1 = .Top + .Height / 2 .Fill.Transparency = -(((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5 > 100) .Line.Transparency = .Fill.Transparency If .Type = msoPicture Then .Visible = .Fill.Transparency = 0 End If End With Next i End Sub
Function rr$(s$) On Error GoTo err With CreateObject("vbscript.regexp") .Global = True .Pattern = "(\s*[AÀ][0-9]{1,2}\S*?[,+])" If Not .test(s) Then Exit Function rr = .Replace(s, "") End With Exit Function err: rr = "Error " & err End Function
[/vba]
вариант с UDF[vba]
Код
Function rr$(s$) On Error GoTo err With CreateObject("vbscript.regexp") .Global = True .Pattern = "(\s*[AÀ][0-9]{1,2}\S*?[,+])" If Not .test(s) Then Exit Function rr = .Replace(s, "") End With Exit Function err: rr = "Error " & err End Function