PlanMyTax

Planning Your Taxes \\ Since 1983

Site Tools


macros
IDDescriptionMacro
em05Highlight Row/s as you move from one cell to another
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Static prevRow As Range
    Dim highlightColor As Long
    highlightColor = RGB(255, 255, 153) ' Light yellow
 
    ' Restore previous row's formatting (remove highlight)
    If Not prevRow Is Nothing Then
        prevRow.EntireRow.Interior.ColorIndex = xlNone
    End If
 
    ' Highlight current row
    Target.EntireRow.Interior.Color = highlightColor
 
    ' Store current row for next time
    Set prevRow = Target
End Sub
em04Color PAN Digits in GST Number to Magenta
Sub ColorPANDigitsInGST()
    Dim c As Range
    Dim txt As String
 
    For Each c In Selection
        txt = c.Value
        If Len(txt) = 0 Then GoTo NextCell
 
        ' Reset entire text to black first
        c.Font.Color = vbBlack
 
        ' Color characters 8 to 11 magenta (only if cell is long enough)
        If Len(txt) >= 11 Then
            c.Characters(8, 4).Font.Color = vbMagenta
        End If
 
NextCell:
    Next c
End Sub
em03Color Text Black and Numbers Magenta for text within a cell or a range : Other Options vbBlack or vbRed or vbGreen or vbYellow or vbBlue or vbMagenta or vbCyan or vbWhite
Sub ColorTextBlackAndNumbersMagenta()
    Dim c As Range, i As Long, ch As String
    Dim txt As String
 
    For Each c In Selection
        txt = c.Value
        c.Font.Color = vbBlack ' reset first
 
        For i = 1 To Len(txt)
            ch = Mid(txt, i, 1)
            If ch Like "[0-9]" Then
                c.Characters(i, 1).Font.Color = vbMagenta
            ElseIf ch Like "[A-Za-z]" Then
                c.Characters(i, 1).Font.Color = vbBlack
            End If
        Next i
    Next c
End Sub
em02Delete all objects from every worksheet like Shapes, Pictures, Charts, Form Controls (buttons, dropdowns, checkboxes), SmartArt and OLEObjects
Sub DeleteAllObjects()
    Dim ws As Worksheet
    Dim shp As Shape
    Dim obj As OLEObject
 
    For Each ws In ThisWorkbook.Worksheets
 
        'Delete Shapes
        For Each shp In ws.Shapes
            shp.Delete
        Next shp
 
        'Delete ActiveX Controls
        For Each obj In ws.OLEObjects
            obj.Delete
        Next obj
 
    Next ws
 
    MsgBox "All objects deleted.", vbInformation
End Sub
em01Remove Conditional Formatting from all sheets
Sub RemoveConditionalFormatting()
    Dim ws As Worksheet
    Dim response As VbMsgBoxResult
 
    response = MsgBox("Remove ALL conditional formatting from aLL sheets?", vbYesNo + vbExclamation)
 
    If response = vbYes Then
        For Each ws In ThisWorkbook.Worksheets
            ws.Cells.FormatConditions.Delete
        Next ws
        MsgBox "Done.", vbInformation
    Else
        MsgBox "Operation cancelled.", vbInformation
    End If
End Sub
macros.txt · Last modified: by admin

Page Tools