Solved

# Add an IF(OR to find replace VBA code

Posted on 2014-08-18
131 Views
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
``````
0
Question by:Seamus2626

LVL 44

Accepted Solution

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
``````
0

LVL 6

Assisted Solution

Hi,

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

Regards,

John
0

LVL 47

Assisted Solution

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
``````
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
``````
Regards
0

Author Closing Comment

Thanks guys!
0

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

#### 759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!