Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Put a single quotation mark in front of numbers in selected cells

Dear Expert:

I need to convert numbers to text and put a tick (') mark/single
quotation mark in front of every one of them.

I would like to have a macro solution and the macro should work ONLY
on selected cells.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Put a single quotation mark in front of numbers in selected cells

This does exactly what you asked for...

Sub AddApostrophe()
Dim C As Range
For Each C In Selection
C.Replace C.Value, "'" & C.Value
Next
End Sub

However, you do not need to put an apostrophe in front of each number to
convert it to text, you can use this simpler macro to change the Cell Format
of the selected cells to Text instead...

Sub ConvertToText()
Selection.NumberFormat = "@"
End Sub

--
Rick (MVP - Excel)



"andreashermle" wrote in message
...
Dear Expert:

I need to convert numbers to text and put a tick (') mark/single
quotation mark in front of every one of them.

I would like to have a macro solution and the macro should work ONLY
on selected cells.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Put a single quotation mark in front of numbers in selected cells

Hi,

Maybe this

Sub sonic()
For Each c In Selection
If IsNumeric(c) Then
c.Value = "'" & c.Value
End If
Next
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"andreashermle" wrote:

Dear Expert:

I need to convert numbers to text and put a tick (') mark/single
quotation mark in front of every one of them.

I would like to have a macro solution and the macro should work ONLY
on selected cells.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Put a single quotation mark in front of numbers in selected cells

On 21 Apr., 16:58, "Rick Rothstein"
wrote:
This does exactly what you asked for...

Sub AddApostrophe()
* Dim C As Range
* For Each C In Selection
* * C.Replace C.Value, "'" & C.Value
* Next
End Sub

However, you do not need to put an apostrophe in front of each number to
convert it to text, you can use this simpler macro to change the Cell Format
of the selected cells to Text instead...

Sub ConvertToText()
* Selection.NumberFormat = "@"
End Sub

--
Rick (MVP - Excel)

"andreashermle" wrote in message

...



Dear Expert:


I need to convert numbers to text and put a tick (') mark/single
quotation mark in front of every one of them.


I would like to have a macro solution and the macro should work ONLY
on selected cells.


Help is much appreciated. Thank you very much in advance.


Regards, Andreas- Zitierten Text ausblenden -


- Zitierten Text anzeigen -


Hi Rick,

thank you very much for your terrific help. Both codes are just fine.
Regards, Andreas
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Put a single quotation mark in front of numbers in selected cells

On 21 Apr., 17:20, Mike H wrote:
Hi,

Maybe this

Sub sonic()
For Each c In Selection
* * If IsNumeric(c) Then
* * * * c.Value = "'" & c.Value
* * End If
Next
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.



"andreashermle" wrote:
Dear Expert:


I need to convert numbers to text and put a tick (') mark/single
quotation mark in front of every one of them.


I would like to have a macro solution and the macro should work ONLY
on selected cells.


Help is much appreciated. Thank you very much in advance.


Regards, Andreas
.- Zitierten Text ausblenden -


- Zitierten Text anzeigen -


Hi Mike,

thank you very much for your professional help. It works fine.
Regards, Andreas
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Single quotation mark in Excel not showing up PALady Excel Discussion (Misc queries) 2 April 3rd 23 04:36 PM
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 1 November 29th 08 07:49 AM
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 0 November 29th 08 05:15 AM
Single quotation mark prefix Chris Hankin[_4_] Excel Programming 5 February 15th 08 02:08 AM
Single or Double Quotation Mark and it comes up twice J.R.HOLMES Setting up and Configuration of Excel 1 December 31st 05 08:51 PM


All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"