Copy and paste a value in a phrase

Emily9093

New Member
Joined
Feb 3, 2016
Messages
5
Hi All,

I am trying to copy and paste value from one cell to another. The value will be pasted after a phrase and in between quotation marks. For example:

Before copy & paste A1: 4567892300 C1: phone number = "" active etc.
After copy & paste A1: 4567892300 C1: phone number = "4567892300" active etc.

I know several ways to copy and paste in VBA, but is having trouble inserting value in a specific location.

Could anyone help me out on this?

Thanks!

Emily
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You want to add the value of A1 into C1 in between the double quotes in C1, is that it?

Just an idea
Code:
Sub GetRangeC1()
    ask = InStr(1, Range("C1"), """")
    Range("C1") = Mid(Range("C1"), 1, ask) & Range("A1") & Mid(Range("C1"), ask + 1, 100)
End Sub
 
Last edited:
Upvote 0
You want to add the value of A1 into C1 in between the double quotes in C1, is that it?

Just an idea
Code:
Sub GetRangeC1()
    ask = InStr(1, Range("C1"), """")
    Range("C1") = Mid(Range("C1"), 1, ask) & Range("A1") & Mid(Range("C1"), ask + 1, 100)
End Sub

Thank you! That was very helpful. Is there a way to apply it to all values in two columns instead of just 2 cells?
 
Upvote 0
like this
Code:
Sub GetRangeC1()
    For I = 1 To Range("C" & Rows.Count).End(xlUp).Row
        ask = InStr(1, Range("C" & I), """")
        Range("C" & I) = Mid(Range("C" & I), 1, ask) & Range("A" & I) & Mid(Range("C" & I), ask + 1, 100)
    Next
End Sub

It will apply to all cells in column C, referencing column A
 
Upvote 0
like this
Code:
Sub GetRangeC1()
    For I = 1 To Range("C" & Rows.Count).End(xlUp).Row
        ask = InStr(1, Range("C" & I), """")
        Range("C" & I) = Mid(Range("C" & I), 1, ask) & Range("A" & I) & Mid(Range("C" & I), ask + 1, 100)
    Next
End Sub

It will apply to all cells in column C, referencing column A

Thank you! It was flawless!
 
Upvote 0
Thanks for the kind words. you are welcome

Hi Momentman,

If I have multiple quotes within column C, and I would like to insert the same phone number from column A to all quotes in column C. How should I code for such scenario?
For example:
Before copy & paste A1: 4567892300 C1: phone number = "35000" active etc.
phone number repeated = "36000" active etc.
.............
After copy & paste A1: 4567892300 C1: phone number = "4567892300" active etc.
phone number repeated = "4567892300" active etc.
......

Here is the revised code I tailored towards the requirements of my project.
Code:
Sub GetRangeC1()
    For I = 2 To Range("U" & Rows.Count).End(xlUp).Row
        ask = InStr(1, Range("U" & I), """")
        Range("U" & I) = Mid(Range("U" & I), 1, ask) & Range("O" & I) & Mid(Range("U" & I), ask + 6, 100)
        If Range("O" & I) = "" Then
                    Range("U" & I) = Mid(Range("U" & I), 1, ask) & Range("O" & I - 1) & Mid(Range("U" & I), ask + 1, 100)
        End If
    Next
End Sub

Thank you for the help!
 
Upvote 0
Try this
Code:
Sub GetRan1geC1()
    For I = 1 To Range("C" & Rows.Count).End(xlUp).Row
        Range("C" & I).Replace What:="""*""", Replacement:="""" & Range("A1") & """", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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