Using “If cell contains” in VBA excel

后端 未结 6 2399
孤独总比滥情好
孤独总比滥情好 2020-12-10 16:55

I\'m trying to write a macro where if there is a cell with the word \"TOTAL\" then it will input a dash in the cell below it. For example:

6条回答
  •  无人及你
    2020-12-10 17:59

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Not Intersect(Target, Range("C6:ZZ6")) Is Nothing Then
    
        If InStr(UCase(Target.Value), "TOTAL") > 0 Then
            Target.Offset(1, 0) = "-"
        End If
    
    End If
    
    End Sub
    

    This will allow you to add columns dynamically and automatically insert a dash underneath any columns in the C row after 6 containing case insensitive "Total". Note: If you go past ZZ6, you will need to change the code, but this should get you where you need to go.

提交回复
热议问题