Excel Help Please
 

Excel Help Please

11 Posts
8 Users
3 Reactions
450 Views
Posts: 53
Free Member
Topic starter
 

Can some on help with a formula to change a charcter from - to ,

I need the forumla to change the character after 10 charceters from the left of the cell

Thanks in advance

 
Posted : 08/05/2025 11:09 am
Posts: 2275
Full Member
 

Is it always the 10th from the left? If so you can simply do:

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

 

Alternatively, this will replace the first instance of "-" with ","

=SUBSTITUTE(A1, "-", ",", 1)

 
Posted : 08/05/2025 11:15 am
BoardinBob reacted
Posts: 14658
Full Member
 

=replace(A1,1,10,",")

 
Posted : 08/05/2025 11:16 am
Posts: 53
Free Member
Topic starter
 

ok the subsitue seems to be working better but it only change 1 instance of it in a cell i want it to keep the 1st istnace of it and remove the others i.e

=SUBSTITUTE(A1, "-", ",", 1)

help - with - this - Formula

would become

Help - with this Formula

 
Posted : 08/05/2025 11:28 am
Posts: 2275
Full Member
 

Erm ok that's a bit trickier.

The last number in the substitute function is which instance of the character to replace, so you can do eg:

=SUBSTITUTE(A1, "-", ",", 2)

to just replace the second one. To replace all dashes with commas EXCEPT the first one, um... I will cheat and resort to AI 😁

Gemini gives me this, which looks insane but works nicely:

=LET(
    text_string, A1,
    char_to_replace, "-",
    replacement_char, ",",
    first_occurrence, FIND(char_to_replace, text_string),
    part_before, LEFT(text_string, first_occurrence),
    part_after, MID(text_string, first_occurrence + 1, LEN(text_string) - first_occurrence),
    replaced_after, SUBSTITUTE(part_after, char_to_replace, replacement_char),
    result, part_before & replaced_after,
    result
)

 

Edit: Does that help? It seems somewhat at odds with your original requirements.

 

Edit 2: Another way of doing it, which is simpler but stupider 😁

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1, "-", "¶", 1), "-", ","), "¶", "-", 1)

 

 
Posted : 08/05/2025 11:40 am
 poly
Posts: 8582
Free Member
 

You can now do regex in excel.

writing good regex requires a very clear spec.

eg “replace all - in the text except the first one” where does the 10th character come in?  Example test cases would be useful.

 
Posted : 08/05/2025 12:50 pm
Posts: 25735
Full Member
 

very clear spec

you need to be mighty sure that you're happy to lose ALL other hyphens, minuses that may be lurking in there

 
Posted : 08/05/2025 1:14 pm
Posts: 3643
Full Member
 

What are you actually trying to do?

  1.  replace the first "-" with ","?
  2. replace the 10th character with a ","?
  3. replace the 10th character with a "," but only if it is "-"?
  4. remove all but the first "-"?
  5. replace the first "-" with a "," and remove all other "-"s?

 

 
Posted : 08/05/2025 2:00 pm
Posts: 10671
Full Member
 

^ is exactly why people hated giving a brief to my analytics team. We'd always come back with a list of things to clarify, half of which the originator didn't have an immediate (or sometimes ever) answer to.

 
Posted : 08/05/2025 3:07 pm
Posts: 2275
Full Member
 

Posted by: thepurist

^ is exactly why people hated giving a brief to my analytics team. We'd always come back with a list of things to clarify, half of which the originator didn't have an immediate (or sometimes ever) answer to.

I work in software development. I feel your pain.

 
Posted : 08/05/2025 3:18 pm
leffeboy reacted
 bubs
Posts: 1332
Full Member
 

To do what you have asked and spec'd out then

= Left (a1, 10) & Substitute (Mid (a1, 11, 999999), " -", " ")

To do what you need 🤷

 
Posted : 08/05/2025 3:47 pm
leffeboy reacted