• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Adding Words|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Adding Words|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosAdding Words
sp_PrintTopic sp_TopicIcon
Adding Words
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
1
September 17, 2019 - 9:03 pm
sp_Permalink sp_Print

Hi folks,
Hope everyone is well.

I need macro to add specific words at the end or front of some words, so I checked myonlinetraininghub.com and I found attached macro and I need your help to enhance it please.

I just want to add ability to choose if I want to add in end or front of some words.

When I run the macro, I should change below cell count. so if there ability to run the macro without change below every time.

CoArray = Sheets("Sheet1").Range("A2:A60").Value
PWArray = Sheets("Sheet1").Range("B2:B51").Value

Thanks;

Marsil

sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1512
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
September 18, 2019 - 9:24 am
sp_Permalink sp_Print

Hi Marsil,

It's not exactly clear to me what you want to do.

When I run the macro, I should change below cell count. so if there ability to run the macro without change below every time.

What do you mean by 'change below cell count' and 'run the macro without change' ?

If you want to add specific words at the front or end of other words, can you please provide examples of what you want.  The file you supplied has a macro that just creates combinations of every word in ColA and Colb.

I just want to add ability to choose if I want to add in end or front of some words

How exactly do you want this to be achieved?

Regards

Phil

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
3
September 18, 2019 - 10:27 am
sp_Permalink sp_Print

Hi Marsil

My guess is you wanted a dynamic range.

Sub AddPublicWord()
Dim CoArray() As Variant
Dim PWArray() As Variant
Dim r As Long
Dim s As Long
Dim i As Long
Dim lrA As Long
Dim lrB As Long

'Find the last row with data
lrA = Cells(Rows.Count, "A").End(xlUp).Row
lrB = Cells(Rows.Count, "B").End(xlUp).Row

i = 2
CoArray = Sheets("Sheet1").Range("A2:A" & lrA).Value
PWArray = Sheets("Sheet1").Range("B2:B" & lrB).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

As for the adding in front/at the back of words we don't know what is it that you want to achieve.

Always attach your expected result as it will be easier for us to understand what you really have in mind.

Sunny

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
4
September 18, 2019 - 11:25 pm
sp_Permalink sp_Print

Hi Sunny & Philip,

I just wanted to send my thanks for all your assistance.

So sorry as I didn't explain by request by all details.

Sunny,  Yes I want a dynamic range and I updated the macro by above code and it is Ok. thank you.

I just want to add new column to add the words in Front, please check column D to see what I mean.

 

Thanks;

Marsil

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
5
September 19, 2019 - 9:18 am
sp_Permalink sp_Print

Hi Marsil

You only need to add this line in red to your code. It just swap the position of the Name and Public Words.

Sub AddPublicWord()
Dim CoArray() As Variant
Dim PWArray() As Variant
Dim r As Long
Dim s As Long
Dim i As Long
Dim lrA As Long
Dim lrB As Long

'Find the last row with data
lrA = Cells(Rows.Count, "A").End(xlUp).Row
lrB = Cells(Rows.Count, "B").End(xlUp).Row

i = 2
CoArray = Sheets("Sheet1").Range("A2:A" & lrA).Value
PWArray = Sheets("Sheet1").Range("B2:B" & lrB).Value
For r = 1 To UBound(CoArray, 1)
For s = 1 To UBound(PWArray, 1)

Cells(i, 4) = PWArray(s, 1) & " " &CoArray(r, 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

Good luck

Sunny

sp_AnswersTopicAnswer
Answers Post
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
6
September 19, 2019 - 8:37 pm
sp_Permalink sp_Print

Thank you very much!

Thanks;

Marsil

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
7
September 20, 2019 - 9:11 am
sp_Permalink sp_Print

No problem

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: baber Tufail
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
drsven
Annie Witbrod
wahab tunde
Cong Le Duc
Faisal Bashir
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27211

 

Member Stats:
Guest Posters: 49
Members: 31880
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.