+ Reply to Thread
Results 1 to 7 of 7

Colouring cells if last character is a space

  1. #1
    Registered User
    Join Date
    11-29-2017
    Location
    belgium
    MS-Off Ver
    Office 365 ProPlus
    Posts
    32

    Colouring cells if last character is a space

    Hello,

    Here below you can find vba code to color cells if the last character or first character is a space.
    I tried the vba code in a test file and it worked, but when I go to the file that has to be checked, an error message appears: "Run-time error '13': Type mismatch".
    If I click on debug, the yellow text line to show the error jumps to "If Left(sheetArr(i, j), 1) = " " Then"

    In the meantime I checked my worksheet and the naming is correct.
    Hope anybody can give me a hint about the error.



    Please Login or Register  to view this content.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Colouring cells if last character is a space

    Not sure about VBA, but this simple formula should work in CF...
    =AND(K2<>"",OR(LEFT(K2,1)=" ",RIGHT(K2,1)=" "))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    11-29-2017
    Location
    belgium
    MS-Off Ver
    Office 365 ProPlus
    Posts
    32

    Re: Colouring cells if last character is a space

    FDibbins, thanks for your suggestion but my range of cells (columns (BP) and rows (2012)) is so big that it is quite impossible to do it on this manner.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Colouring cells if last character is a space

    OK so perhaps you could incorporate that test into your code?

    All you really need to test of is...
    - the cell isnt blank
    - LEFT(K2,1)=" "
    - RIGHT(K2,1)=" "

  5. #5
    Registered User
    Join Date
    11-29-2017
    Location
    belgium
    MS-Off Ver
    Office 365 ProPlus
    Posts
    32

    Re: Colouring cells if last character is a space

    Quote Originally Posted by FDibbins View Post
    OK so perhaps you could incorporate that test into your code?

    All you really need to test of is...
    - the cell isnt blank
    - LEFT(K2,1)=" "
    - RIGHT(K2,1)=" "
    Am I understand you correctly that I need to insert these tests in each cell again? Remember as explained: I have thousands of cells to check. Only workable quick manner is vba if you ask me. I'm working for a big company and may not modify cells, I may only add macro's to check some things because this file will be used for other departments too.

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Colouring cells if last character is a space

    Hi,

    Try the following code. The first Macro that uses 'UsedRange' tests all cells in the rectangular area. The second Macro only tests cells that have a typed in value, or a value created with a formula.
    Please Login or Register  to view this content.
    Lewis

  7. #7
    Registered User
    Join Date
    11-29-2017
    Location
    belgium
    MS-Off Ver
    Office 365 ProPlus
    Posts
    32

    Re: Colouring cells if last character is a space

    Quote Originally Posted by LJMetzger View Post
    Hi,

    Try the following code. The first Macro that uses 'UsedRange' tests all cells in the rectangular area. The second Macro only tests cells that have a typed in value, or a value created with a formula.
    Please Login or Register  to view this content.
    Lewis
    Thanks Lewis

+ 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] Extract first character after every space
    By Ratso in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-22-2019, 12:16 PM
  2. Replies: 7
    Last Post: 02-07-2019, 05:25 PM
  3. Replies: 3
    Last Post: 11-13-2018, 02:47 AM
  4. Time formatted cells not summing when pasted due to unwanted space character
    By chatters1969 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-19-2015, 08:48 AM
  5. How to remove space after a particular character
    By sugaprasad in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-20-2015, 05:02 AM
  6. [SOLVED] Need to add space after every 4th Character
    By yus786 in forum Excel General
    Replies: 10
    Last Post: 04-04-2012, 06:08 AM
  7. Adding a space after a hex character
    By jaango123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2011, 05:34 AM

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