Skip to content

Instantly share code, notes, and snippets.

@naturallucky
Created November 1, 2020 16:34
Show Gist options
  • Save naturallucky/f905fb0c2c72f8d1a3bc79903b11f96d to your computer and use it in GitHub Desktop.
Save naturallucky/f905fb0c2c72f8d1a3bc79903b11f96d to your computer and use it in GitHub Desktop.
[Excel vba]Insert string at head of cell when matching
Sub マッチパターンの時だけセル先頭に文字追加()
' ee8dff -> #ee8dff
Dim c As Range
Dim v As String
Dim reRGB, reSharp6, reSharp3 As Object 'New RegExp
Dim mc As Object 'MatchCollection
Set reSharp6 = CreateObject("VBScript.RegExp")
reSharp6.Pattern = "(^[0-9a-fA-F]{1,6}$)"
reSharp6.Global = True
For Each c In Selection
''c に対する処理
v = c.Value
Set mc = reSharp6.Execute(v)
If mc.Count > 0 Then
v = "#" & v
c.Value = v
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment