Forum

Adding Public words
 
Notifications
Clear all

Adding Public words

7 Posts
3 Users
0 Reactions
63 Views
(@ehab1511)
Posts: 31
Trusted Member
Topic starter
 

Hi,

Could you please help me to create macro to add Public words at the end of names as below.

Public words: Corp     Inc.    Company     CO      Corporation   co,ltd

Name: Apple

Macro result: 

Apple Corp     

Apple Inc.    

Apple Company     

Apple Corporation

Apple co,ltd

Please check attached file to get sample.

Thanks;

Ehab

 
Posted : 06/05/2019 7:04 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Try this

Sub AddPublicWord()

Dim CoArray() As Variant
Dim PWArray() As Variant
Dim r As Long
Dim s As Long
Dim i As Long

i = 2

CoArray = Sheets("Sheet1").Range("A2:A4").Value
PWArray = Sheets("Sheet1").Range("B2:B7").Value
For r = 1 To UBound(CoArray, 1)
For s = 1 To UBound(PWArray, 1)
Cells(i, 5) = CoArray(r, 1) & " " & PWArray(s, 1)
i = i + 1
Next s
Next r

End Sub

 
Posted : 06/05/2019 11:52 pm
(@ehab1511)
Posts: 31
Trusted Member
Topic starter
 

You are amazing! Thank you so much!

I just want to repeat the name as below.

Name Public words New Name
Apple Corp Apple Corp
Apple Inc. Apple Inc.
Apple Company      Apple Company     
Apple CO      Apple CO     
Apple Corporation    Apple Corporation   
Apple co,ltd Apple co,ltd

Please check attached file.

 
Posted : 07/05/2019 4:33 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

Just concatenate the strings e.g. in C2

  =A2&" "&B2

See attached.

Regards

Phil

 
Posted : 07/05/2019 8:08 am
(@ehab1511)
Posts: 31
Trusted Member
Topic starter
 

Hi Phil & Sunny,

Thank you very much

I just want to update the macro by adding new column and will contain the Original Name "before we add the public words".

I don't to repeat any value in column B.

Please check attached file.

 

Thank;

Ehab

 
Posted : 07/05/2019 12:28 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Try this

Sub AddPublicWord()
Dim CoArray() As Variant
Dim PWArray() As Variant
Dim r As Long
Dim s As Long
Dim i As Long
i = 2
CoArray = Sheets("Sheet1").Range("A2:A4").Value
PWArray = Sheets("Sheet1").Range("B2:B20").Value
For r = 1 To UBound(CoArray, 1)
For s = 1 To UBound(PWArray, 1)
Cells(i, 5) = CoArray(r, 1) & " " & PWArray(s, 1)
Cells(i, 6) = CoArray(r, 1)
i = i + 1
Next s
Next r
End Sub

 
Posted : 07/05/2019 7:03 pm
(@ehab1511)
Posts: 31
Trusted Member
Topic starter
 

Wow! Thank you so much. This is awesome. This will save me so much time.

 
Posted : 08/05/2019 4:47 pm
Share: