If a cell contains text
Macro Title:
|
Worksheet Variable:
|
Row Reference Variable:
|
Worksheet Name:
|
Test From Row Number:
enter the first row number of a cell from which you want to begin testing |
Test To Row Number:
enter the last row number of a cell which you want to test |
Test Column Number:
enter the column number of the column that captures the cells that you want to test |
Output Column Number:
enter the column number of the column in which you want to return the results |
Value if test is True:
enter the value that you want returned if a cell contains text |
Value if test is False:
enter the value that you want returned if a cell does not contain text |
First Comment:
' |
Second Comment:
' |
Sub If_a_cell_contains_text_with_the_COUNTIF_function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell contains text, using the COUNTIF function with a For Loop, and then return a specified value
For x = 5 To 8
On Error Resume Next
If Application.WorksheetFunction.CountIf(ws.Cells(x, 2)) > 0 Then
ws.Cells(x, 3) = "Contains Text"
Else
ws.Cells(x, 3) = "No Text"
End If
Next x
End Sub
Sub If_a_cell_contains_text_with_the_COUNTIF_function()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate if a cell contains text, using the COUNTIF function with a For Loop, and then return a specified value
For x = 5 To 8
For x = 5 To 8
On Error Resume Next
If Application.WorksheetFunction.CountIf(ws.Cells(x, 2)) > 0 Then
ws.Cells(x, 3) = "Contains Text"
Else
ws.Cells(x, 3) = "No Text"
End If
Next x
End Sub