How to keep the leading apostrophe from a cell when storing into a string variable?

wiseone

Board Regular
Joined
Mar 14, 2015
Messages
145
I have some code that I can execute no matter which cell on a row is selected. When my macro begins, it copies certain cells in the selected row into string variables. I later paste the string variable into another cell on a different tab. When I do this, if there was a leading apostrophe, the leading apostrophe is lost.

How can I maintain the apostrophe if it is there?

Here is an excerpt of the code which is not keeping the leading apostrophe:

Dim Active_Row as Integer
Dim CustomerPO as String

Active_Row = Selection.Row
CustomerPO = Cells(Active_Row, Range("Customer_PO").Column)
Range("Conf_PO) = CustomerPO

Thanks in advance!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thank you. Here is the solution for my code from the above link:


VBA Code:
Dim Active_Row as Integer
Dim CustomerPO as String

Active_Row = Selection.Row
IF Cells(Active_Row, Range("Customer_PO").Column).PrefixCharacter = "'" Then
CustomerPO = "'" & Cells(Active_Row, Range("Customer_PO").Column)
Else
CustomerPO = Cells(Active_Row, Range("Customer_PO").Column)
End If

Range("Conf_PO") = CustomerPO
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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