Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default searching names for '*', replacing it with first name

Hello:

I have an Excel workbook with the first column of Customer Name. This
column contains the names of both businesses and personal customers.
Personal customers have the '*' symbol in front of their last name
(i.e. ROBERT A *SMITH). I would like to create a macro that scans each
customer name for an asterisk - if one exists, take the personal
customer's first name and place it in an adjacent column. I plan to use
this new column as the greeting in a mail merge. If there is no
asterisk in a customer name then it is a business and the entire
business name would be used in the greeting.
Example:

Robert A *Smith in cell A1 would be changed to Robert in cell B1...for
"Dear Robert:"
Picture Perfect Inc in cell A1 would be Picture Perfect Inc in cell
B1...for "Dear Picture Perfect Inc:"

Having this in a macro would be ideal because it could run at the end
of a series of macros I have that run in sucession.

Thanks in advance!
-Badi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default searching names for '*', replacing it with first name

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim iPos As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
iPos = InStr(Cells(i, "A").Value, "*")
If iPos 0 Then
Cells(i, "B").Value = Right(Cells(i, "A").Value, _
Len(Cells(i, "A").Value) - iPos)
Cells(i, "A").Value = Left(Cells(i, "A").Value, iPos - 1)
End If
Next i
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...
Hello:

I have an Excel workbook with the first column of Customer Name. This
column contains the names of both businesses and personal customers.
Personal customers have the '*' symbol in front of their last name
(i.e. ROBERT A *SMITH). I would like to create a macro that scans each
customer name for an asterisk - if one exists, take the personal
customer's first name and place it in an adjacent column. I plan to use
this new column as the greeting in a mail merge. If there is no
asterisk in a customer name then it is a business and the entire
business name would be used in the greeting.
Example:

Robert A *Smith in cell A1 would be changed to Robert in cell B1...for
"Dear Robert:"
Picture Perfect Inc in cell A1 would be Picture Perfect Inc in cell
B1...for "Dear Picture Perfect Inc:"

Having this in a macro would be ideal because it could run at the end
of a series of macros I have that run in sucession.

Thanks in advance!
-Badi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default searching names for '*', replacing it with first name

You could do this with a formula in B1,

=IF(ISERROR(FIND("*",A1)),A1,LEFT(A1,FIND(" ",A1)-1))

" wrote:

Hello:

I have an Excel workbook with the first column of Customer Name. This
column contains the names of both businesses and personal customers.
Personal customers have the '*' symbol in front of their last name
(i.e. ROBERT A *SMITH). I would like to create a macro that scans each
customer name for an asterisk - if one exists, take the personal
customer's first name and place it in an adjacent column. I plan to use
this new column as the greeting in a mail merge. If there is no
asterisk in a customer name then it is a business and the entire
business name would be used in the greeting.
Example:

Robert A *Smith in cell A1 would be changed to Robert in cell B1...for
"Dear Robert:"
Picture Perfect Inc in cell A1 would be Picture Perfect Inc in cell
B1...for "Dear Picture Perfect Inc:"

Having this in a macro would be ideal because it could run at the end
of a series of macros I have that run in sucession.

Thanks in advance!
-Badi


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default searching names for '*', replacing it with first name

You can also use DataText To Columns with a * delimiter

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Bob Phillips" wrote in message
...
Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim iPos As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
iPos = InStr(Cells(i, "A").Value, "*")
If iPos 0 Then
Cells(i, "B").Value = Right(Cells(i, "A").Value, _
Len(Cells(i, "A").Value) - iPos)
Cells(i, "A").Value = Left(Cells(i, "A").Value, iPos - 1)
End If
Next i
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...
Hello:

I have an Excel workbook with the first column of Customer Name. This
column contains the names of both businesses and personal customers.
Personal customers have the '*' symbol in front of their last name
(i.e. ROBERT A *SMITH). I would like to create a macro that scans each
customer name for an asterisk - if one exists, take the personal
customer's first name and place it in an adjacent column. I plan to use
this new column as the greeting in a mail merge. If there is no
asterisk in a customer name then it is a business and the entire
business name would be used in the greeting.
Example:

Robert A *Smith in cell A1 would be changed to Robert in cell B1...for
"Dear Robert:"
Picture Perfect Inc in cell A1 would be Picture Perfect Inc in cell
B1...for "Dear Picture Perfect Inc:"

Having this in a macro would be ideal because it could run at the end
of a series of macros I have that run in sucession.

Thanks in advance!
-Badi





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing a list of codes with names Mortir Excel Worksheet Functions 3 May 30th 08 04:06 PM
Replacing A,B,C column names to other names Lisa H Excel Discussion (Misc queries) 4 July 11th 07 06:28 PM
Replacing Range Names Jim May Excel Discussion (Misc queries) 2 October 25th 06 12:54 PM
Cell searching and Replacing Graham Feeley Excel Discussion (Misc queries) 3 August 5th 05 04:42 PM
replacing just the sheet names within formulas Jeanne Criez Excel Worksheet Functions 1 January 4th 05 06:27 PM


All times are GMT +1. The time now is 09:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"