huiyin9218
Board Regular
- Joined
- Aug 7, 2018
- Messages
- 53
Hi,
How do i write a code to find multiple words (for example: AM and PM) in a column and assign a number "1" at the next 2 columns.
I'm able to find "AM" and assign 1 next to it but i don't know how to add PM into the code and move the number "1" to the next column.
I would be so grateful for your help.
Sub MarkText()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Set ws = ThisWorkbook.Sheets("Sheet1")
Const Text2Find = "AM"
Dim cel As Range
For Each cel In ws.UsedRange.Columns("A").Cells
If InStr(cel.Value, Text2Find) > 0 Then
cel.Offset(0, 1) = 1
Else
cel.Offset(0, 1).ClearContents
End If
Next cel
Next ws
End Sub
How do i write a code to find multiple words (for example: AM and PM) in a column and assign a number "1" at the next 2 columns.
I'm able to find "AM" and assign 1 next to it but i don't know how to add PM into the code and move the number "1" to the next column.
I would be so grateful for your help.
Sub MarkText()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Set ws = ThisWorkbook.Sheets("Sheet1")
Const Text2Find = "AM"
Dim cel As Range
For Each cel In ws.UsedRange.Columns("A").Cells
If InStr(cel.Value, Text2Find) > 0 Then
cel.Offset(0, 1) = 1
Else
cel.Offset(0, 1).ClearContents
End If
Next cel
Next ws
End Sub