+ Reply to Thread
Results 1 to 12 of 12

If cell starts with semicolon, remove semicolon

  1. #1
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    If cell starts with semicolon, remove semicolon

    Hello. I have some VBA script that contains an Excel formula that is not working for me. If I copy the formula directly into Excel and run it I get the correct result. If I run it from VBA I just get a '0' (zero) in the cell. Thanks.

    My script:

    ' For Each cell In [Q2:Q3]
    ' cell.Formula = "=(LEFT(Q2,1)="";"",RIGHT(Q2,LEN(Q2)-1),Q2"
    ' Next cell

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: If cell starts with semicolon, remove semicolon

    try this one

    "=IF(LEFT(Q2,1)="";"",RIGHT(Q2,LEN(Q2)-1),Q2)"
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: If cell starts with semicolon, remove semicolon

    My mistake. In my original post I forgot IF and the ). My script is just like you have it. It does not work from VBA but works if I copy it into Excel. Thanks.

  4. #4
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: If cell starts with semicolon, remove semicolon

    Instead of putting the results in the same column, I put the results in the next column over. It works like that.

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: If cell starts with semicolon, remove semicolon

    You get better help with your question if you add a small example of your Excel file, without confidential infomation on this forum. Including your code.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,788

    Re: If cell starts with semicolon, remove semicolon

    How about
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: If cell starts with semicolon, remove semicolon

    Worked great Fluff13. Thanks!!

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,788

    Re: If cell starts with semicolon, remove semicolon

    You're welcome & thanks for the feedback.

  9. #9
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: If cell starts with semicolon, remove semicolon

    I have one more question if you do not mind Fluff13. I am just working with a small sampling of what will be a large spreadsheet. Because of that and speed considerations, I changed the code to read like below. It works fine, however, some cells begin with 1 or 2 or 3 or 4 semicolons. I want to be able to loop through each cell in my column until all the leading semicolons are gone. I have tried but not luck yet. The code below will only remove 1 semicolon. I am thinking I either need to incorporate and If statement or a Do while loop but I just do not know how in this context.

    # With ThisWorkbook.Worksheets("Sheet1")
    # lastrow = .Cells(.Rows.Count, 1).End(x1Up).Row
    # With Range("Q2:Q" & lastrow)
    #.Value = Evaluate(Replace("IF(LEFT(@,1)="";"",replace(@,1,1,""""),@)", "@", .Address))
    # End With
    Last edited by ngenova; 08-05-2020 at 05:18 PM.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,788

    Re: If cell starts with semicolon, remove semicolon

    Do you have any semi-colons that need to remain?

  11. #11
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: If cell starts with semicolon, remove semicolon

    Yes, if they are not at the beginning of the cell. I just want to remove the ones that are at the beginning. ex.... ;;savings;loan;car I would just want to get rid of the 2 at the beginning.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,023

    Re: If cell starts with semicolon, remove semicolon

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Remove Every data from Specific Columns before First Semicolon from Left Side
    By hjaspaul in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-11-2017, 05:22 AM
  2. [SOLVED] Keep first word in each line, separate by semicolon and remove everything else
    By adh2 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-14-2015, 12:58 PM
  3. [SOLVED] Remove test beween space and semicolon in a cell
    By Niclal in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2014, 09:56 AM
  4. Replies: 4
    Last Post: 05-11-2013, 10:47 PM
  5. Splitting contents of a cell at a semicolon
    By SALLstice in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2009, 08:43 AM
  6. how do i make a semicolon appear in every cell
    By paul in forum Excel General
    Replies: 2
    Last Post: 08-10-2006, 06:00 PM
  7. [SOLVED] semicolon delimiter in a cell
    By coco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2005, 06:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1