Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Add an IF(OR to find replace VBA code

I need to check for HRI* as well as HRI

Can someone add that line to the below sub

Many thanks

Sub InputHRI_WLA()
    Dim i As Long
    Dim lastRow As Long

    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 2 To lastRow
 
    
        If Cells(i, 2).value = "HRI " Then
            Cells(i, 15).value = "HRI"
        End If
    Next i
 End Sub

Open in new window

0
Seamus2626
Asked:
Seamus2626
3 Solutions
 
aikimarkCommented:
By "HRI*"  do you mean an actual asterisk character or a wildcard character (zero or more of any character)?
If physical character, then
Sub InputHRI_WLA()
    Dim i As Long
    Dim lastRow As Long

    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 2 To lastRow
        If (Cells(i, 2).value = "HRI ") OR (Cells(i, 2).value = "HRI*") Then
            Cells(i, 15).value = "HRI"
        End If
    Next i
 End Sub

Open in new window

0
 
johnb25Commented:
Hi,

Replace your If with this:
        If Cells(i, 2).Value Like "HRI*" Then
            Cells(i, 15).Value = "HRI"

Regards,

John
0
 
Rgonzo1971Commented:
Hi,

Do you want to replace HRI* with HRI

Sub InputHRI_WLA()
    Dim i As Long
    Dim lastRow As Long

    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 2 To lastRow
 
    
        If Cells(i, 2).value = "HRI " Or Cells(i, 2).value = "HRI*"  Then
            Cells(i, 15).value = "HRI"
        End If
    Next i
 End Sub

Open in new window

Or do you want to replace everything beginning with HRI with HRI


Sub InputHRI_WLA()
    Dim i As Long
    Dim lastRow As Long

    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 2 To lastRow
 
    
        If Cells(i, 2).value Like "HRI*" Then
            Cells(i, 15).value = "HRI"
        End If
    Next i
 End Sub

Open in new window

Regards
0
 
Seamus2626Author Commented:
Thanks guys!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now