Using “If cell contains” in VBA excel

后端 未结 6 2396
孤独总比滥情好
孤独总比滥情好 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:42

    This does the same, enhanced with CONTAINS:

    Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, Char As String)
    Dim I As Long
    Dim xRet As String
    For I = 1 To LookupRange.Columns(1).Cells.Count
         If InStr(1, LookupRange.Cells(I, 1), LookupValue) > 0 Then
            If xRet = "" Then
                xRet = LookupRange.Cells(I, ColumnNumber) & Char
            Else
                xRet = xRet & "" & LookupRange.Cells(I, ColumnNumber) & Char
            End If
        End If
    Next
    SingleCellExtract = Left(xRet, Len(xRet) - 1)
    End Function
    

提交回复
热议问题