Replace function for partial characters

GerrardSVK

New Member
Joined
Sep 18, 2023
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone could someone help me I just need to write simple macro that will change number from this format: 1.234 into format using comma instead of dot : 1,234
Also I need to change sign of degrees into nothing. So if there will be some number like this 1.234° final result will be 1,234.

I tried this but dont work:
Sub Replace()

Workbooks(2).ActiveSheet.Range("G9:G136").Replace What:=".", Replacement:=","
Workbooks(2).ActiveSheet.Range("G9:G136").Replace What:="°", Replacement:=""

End Sub

I think there have to be additional xlPart defined or something.
 
OK I ran the code on column D (D9:D136).
Before:
2.kus_kavita3.xlsx
D
973.300°
105.5
1151.6
1248
1338.3
1436.95
150
1630
170
1829
1920.8
2016.3
2110.4
226
236
2410
252
2616
2722.6
281.9
2916.4
3010.1
310
326
336
3410.4
3516.2
3610
3716
3822.6
391.9
4030
419
422
430
440
450
460
470
4816.3
4910.4
506
516
5210
532
5416
5522.6
561.9
5716.4
5810.1
590
606
616
6210.4
6316.2
6410
6516
6622.6
671.9
6830
699
702
710
720
730
740
750
7616.15
7721.4
7812
7911.5
8025
8117
821.8
8321.5
8415.9
850
862.3
8712
8812
8916.3
9021.3
9111.5
9217
9325
941.8
9530
963.7
9712.7
9812
992.7
1000
1010
1020
1030
1040
10513.9
10611.9
10711
10811.7
1090.8
1100.8
11130.000°
1123
1131.2
11490.000°
1152.8
1162.8
11724.9
11825.8
11927.8
12021
12111.2
12213.1
12313.9
12414
1256
12612
1274
1283.25
129250
130116.3
13158.6
132252.7
13362.3
134142.5
1352.9
1362.9
2.kus_kavita3


After:
2.kus_kavita3.xlsx
D
973,300
105,5
1151,6
1248
1338,3
1436,95
150
1630
170
1829
1920,8
2016,3
2110,4
226
236
2410
252
2616
2722,6
281,9
2916,4
3010,1
310
326
336
3410,4
3516,2
3610
3716
3822,6
391,9
4030
419
422
430
440
450
460
470
4816,3
4910,4
506
516
5210
532
5416
5522,6
561,9
5716,4
5810,1
590
606
616
6210,4
6316,2
6410
6516
6622,6
671,9
6830
699
702
710
720
730
740
750
7616,15
7721,4
7812
7911,5
8025
8117
821,8
8321,5
8415,9
850
862,3
8712
8812
8916,3
9021,3
9111,5
9217
9325
941,8
9530
963,7
9712,7
9812
992,7
1000
1010
1020
1030
1040
10513,9
10611,9
10711
10811,7
1090,8
1100,8
11130,000
1123
1131,2
11490,000
1152,8
1162,8
11724,9
11825,8
11927,8
12021
12111,2
12213,1
12313,9
12414
1256
12612
1274
1283,25
129250
130116,3
13158,6
132252,7
13362,3
134142,5
1352,9
1362,9
2.kus_kavita3
WTF It didnt work for me like this :D if i have number for example 73.541° result is 73 541
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
WTF It didnt work for me like this :D if i have number for example 73.541° result is 73 541
It might have something to do with regional/local settings. In any event, I think I've reached the limit of what help I can render. Hopefully someone else will have an answer for you. Good luck, and best wishes.
 
Upvote 0
It might have something to do with regional/local settings. In any event, I think I've reached the limit of what help I can render. Hopefully someone else will have an answer for you. Good luck, and best wishes.
Thank you anyway you help maybe I will find it on my own.
 
Upvote 0
The result you got seems to suggest that the period . was replaced with a space " " instead of a comma ,
VBA Code:
Sub test()
  Call ReplaceDecimal(Workbooks(3).ActiveSheet.Range("G9:G136"))
  Call ReplaceDegree(Workbooks(3).ActiveSheet.Range("G9:G136"))
End Sub
Sub ReplaceDecimal(rng As Object)
  Dim r As Range
  For Each r In rng
    r.Value = "'" & Replace(r.Text, ".", ",")
  Next
End Sub
Sub ReplaceDegree(rng As Range)
  Dim r As Range
  For Each r In rng
    r.Value = "'" & Replace(r.Text, "°", "")
  Next
End Sub

Hi I made this work for me but it make not properlz form of data I need this work that it converts number from for example 75.258° into 75,258 but there is something like change mark in cell.

see image. How do I get rid of it? Dont you know?

1696938742461.png
 
Upvote 0
What does the formula
Excel Formula:
=UNICODE(RIGHT(F9,1))
return (assuming the cell the arrow is pointing at is F9)?
 
Upvote 0
Try something like this

=REPLACE(A2,10,1,"")

Description of formula:
A2 = Cell
Number of spaces to where you want new char
# of new char
Char ","

Kind regards,

Julie Bunavicz
 
Upvote 0
If you are asking quite literally how to get rid of the "change mark", I'm assuming you mean the green arrow, you need to turn off background error checking.
 

Attachments

  • exceloptions.jpg
    exceloptions.jpg
    127.1 KB · Views: 5
Upvote 0
If you are asking quite literally how to get rid of the "change mark", I'm assuming you mean the green arrow, you need to turn off background error checking.
I am afraid that he is not asking about the green arrow. He asking about "'".

@GerrardSVK
This is the mark that makes your value become a text and make the necessary changes. Excel is warning you because it is not a value anymore.
If you want to switch from "." to "," and still keep it a decimal number, there are only 3 legit ways:
1. Go to Windows Control Panel and change the delimiter preference from your regional settings.
2. Go to Excel settings. Click Advanced. Under Editing options, clear the Use system separators check box. Change the default Decimal separator.
3. Convert your data into a table. Select the table and Go to Data tab then click Import Data from Table or Range. In the query window Right Click to column. Select Replace and replace the degree sign. Then change the column type using Locale Settings and select a country like Turkey where the decimal seperator is ",". Save and Close the query.

These are the best options I can think of.
 
Upvote 0
The apostrophe to make it text? Copy a blank cell. Select the range with the numbers preceded with the quote mark. Right click and click on Paste Special, then select Add.
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

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