I need to create a macro that will find and replace the city name in a single sentence from a list of 975 names.
I need the result to generate 975 sentences with the unique city name.
How do i do this?
I need to create a macro that will find and replace the city name in a single sentence from a list of 975 names.
I need the result to generate 975 sentences with the unique city name.
How do i do this?
Hi, kgb951,
why not use formulas to do this? You split up your sentence and leave the city name open and then put it together.
simple example
A1 has "Welcome to "
B1 has " for the festival"
Your list resides from A10 down. Put the following formula in B10:
Please mind the absolute references to A1 and B1.![]()
=$A$1 & A10 & $B$1
If it´s not what you are after please give some more details about where the lists resides as well as the sentence and where it shall be placed.
Ciao,
Holger
I need to replace the word city in this line of code:
<a href="http://t.com/idx/?idx-q-Cities%3C0%3E=City">City Homes for Sale</a>
As you can see, City occurs 2 times.
I have a list of 975 city names. I want to generate this line of code 975 times each with a unique city name.
Examples of city name:
Jackson
Jacumba
Jamul
Janesville
Johnson Valley
Jonesville
Joshua Tree
Julian
June Lake
How can this be done?
assuming the list of 975 cities is in column A and you want the sentences in column B
![]()
Sub test() Dim X As Integer For X = 1 To 975 Cells(X, 2) = "<a href=" & Chr(34) & "http://t.com/idx/?idx-q-Cities%3C0%3E=" & Cells(X, 1) & Chr(34) & ">" & Cells(X, 1) & " Homes for Sale</a>" Next X End Sub
note: Use chr(34) for the " because if you include it normally, Excel will not know you want it as part of the string.
or something like
![]()
Sub ert() Dim arrCities, i& Const s As String = "<a href=""http://t.com/idx/?idx-q-Cities%3C0%3E=City"">City Homes for Sale</a>" With Range("A1", Cells(Rows.Count, 1).End(xlUp)) arrCities = .Value For i = 1 To UBound(arrCities) arrCities(i, 1) = Replace(s, "City", arrCities(i, 1)) Next i .Offset(, 1).Value = arrCities End With End Sub
I used niko's code and it worked! Thanks for much for your help guys!
@ kgb951
Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
Thanks.
Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks