Wednesday, 22 July 2026

How to Convert Numbers to Roman Numerals in Excel Using VBA Macro

 Sub ConvertToRoman()

    Dim cell As Range

    For Each cell In Selection

        If IsNumeric(cell.Value) And cell.Value > 0 And cell.Value < 4000 Then

            cell.Value = Application.WorksheetFunction.Roman(cell.Value)

        End If

    Next cell

End Sub

Tuesday, 14 July 2026

VBA Macro To Fill Cells Automatically

 Sub ApplyHexColors()

    Dim cell As Range

    Dim hexVal As String

    Dim r As Integer, g As Integer, b As Integer

    

    On Error Resume Next

    For Each cell In Selection

        ' Strip the "#" if present

        hexVal = Replace(cell.Value, "#", "")

        

        If Len(hexVal) = 6 Then

            ' Convert Hex to RGB

            r = CInt("&H" & Mid(hexVal, 1, 2))

            g = CInt("&H" & Mid(hexVal, 3, 2))

            b = CInt("&H" & Mid(hexVal, 5, 2))

            

            ' Apply as background fill

            cell.Interior.Color = RGB(r, g, b)

        End If

    Next cell

End Sub