remove salutations

rakesh seebaruth

Active Member
Joined
Oct 6, 2011
Messages
303

Dear Guys

In Column A from A1:A500, I have e.g. Mr John Smith and Mr Mick Steeve


I need a formula or vba that would remove Mr and Mr and paste it in cell B

Thanks in advance.

regards

rakesh

 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Re: remove saluations

Hi , I modified my original code.

Try this..
Code:
Sub Sal()

Dim mStr  As String
Dim lastrow As Long
Dim arr 'As String
lastrow = Cells(Rows.count, "A").End(xlUp).Row
For i = 1 To lastrow
mStr = ActiveSheet.Range("A" & i)
arr = Array("Mr", "Mrs", "Dr", "Prof")
 c = 0
For j = 1 To Len(mStr)
 sStr = Mid(mStr, j, 2)
 For k = 0 To 3
 If sStr = arr(k) Then
 c = c + 1
 If c > 1 Then sal = sal & " AND "
  sal = sal & sStr
End If
  Next k
Next j
 ActiveSheet.Range("B" & i) = sal
sal = ""
Next i

end sub

PS: Don't forget to hit the thumbs up if you like the solution ;)


d9028099ae687be4a9cbdb01c38827ac.gif
 
Last edited:
Upvote 0
Re: remove saluations

Try this...
Code:
'Modified


Dim mStr  As String
Dim lastrow As Long
Dim arr 'As String
lastrow = Cells(Rows.count, "A").End(xlUp).Row
For i = 1 To lastrow
mStr = ActiveSheet.Range("A" & i)
arr = Array("Mr", "Mrs", "Dr")
 c = 0
For j = 1 To Len(mStr)
 sStr = Mid(mStr, j, 2)
  For k = 0 To 2
 If sStr = arr(k) Then
 c = c + 1
   For l = 0 To 2
sStr = Mid(mStr, j, 3)
 If sStr = arr(k) Then
 c = c + 1
 End If
Next l
 If c > 1 Then sal = sal & " AND "
  sal = sal & sStr
End If
  Next k
Next j
 ActiveSheet.Range("B" & i) = sal
sal = ""
Next i
 
Last edited:
Upvote 0
Re: remove saluations

can you translate this to vba for me please
If you have a preferred or required method, best to state that up front so the job doesn't have to be done twice. ;)

Try
Code:
Sub Salutations()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate(Replace("if(#="""","""",trim(#))", "#", .Offset(, -1).Address))
    .Value = Evaluate(Replace(Replace("trim(mid(substitute(#,"" "",rept("" "",20)),20,20))&if(isnumber(find(^,#)),^&mid(#,find(^,#)+5,find("" "",#,find(^,#)+5)-find(^,#)-5),"""")", "#", .Address), "^", """ AND """))
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top