Posts

Showing posts from January, 2021

Excel VBA using Evaluate() function to turn calling cell to RGB found in target cell

This function sets the CURRENT cell value to an RGB based on the target cell- Uses REGEX 5.5 [ ✓ ]Microsoft VBScript Regular Expressions 5.5 Function SetCellColor ( X As Range ) As String Dim re As New RegExp Dim MC As MatchCollection Dim SM As SubMatches Dim RGB As String Dim AC As Range ''What cell is calling: ''https://www.mrexcel.com/board/threads/function-determining-what-cell-it-is-being-called-from.51343/ Set AC = X.Parent.Cells ( Excel.Application.Caller.Row , Excel.Application.Caller.Column ) re.Pattern = ( "(\d{3}).?(\d{3}).?(\d{3})" ) If re.Test ( X.Value ) Then Set MC = re.Execute ( X.Value ) Set SM = MC.Item ( 0 ). SubMatches RGB = SM ( 0 ) & ", " & SM ( 1 ) & ", " & SM ( 2 ) RGB = "SetRGB(" & AC.Address ( False , False ) & ", " & RGB &