Enforce string's format to: 65545,4324,65756 and not: 9.61174259958739E+141 [VBA]

pitaszek

Board Regular
Joined
Jul 20, 2012
Messages
85
I need to have a list of IDs in following format:
56546,933655,7546,23435,54,4454

but if I put it this way it's changed to mathematical notation, eg:
9.61174259958739E+141

I need to keep the format with no spaces after each comma and without a need to add '' ' " before it to enforce string.

My macro generally takes the list of numbers from a column and puts it horizontally with commas.

Any ideas?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I don't get this, so I'm unsure what you mean

When I try to paste that string into Excel, it stays as it is. My cells are formatted as "general".
Likewise if I use VBA [selection.value = "56546,933655,7546,23435,54,4454"], it also pastes as text

Suggestions:
- format your Excel range as text prior to writing the value in
- paste your code here so I can understand the issue better
 
Upvote 0
Hello baitmaster,

Please try this and tell me what is pasted:

Code:
Sub test()
Dim value As String
vale = "43545,5757,3422,46578,5653,3454"
ActiveCell.value = vale
End Sub

Do you have Amer or EU number format?

Cheers,
Witek
 
Upvote 0
I'm in UK so using UK, formats. Different date formats to US (dd/mm/yyyy) but different numeric formats to EU (123,456.78 for 123k to 2 decimal places)

Strangely your code passed a number into Excel, but text when I substituted the value from your original post

I suggest the following fix:
Code:
With ActiveCell
    .NumberFormat = "@"
    .value = vale
End With
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,465
Members
448,965
Latest member
grijken

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