+ Reply to Thread
Results 1 to 6 of 6

extract last 6 characters from a string in IF Then statement

  1. #1
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    extract last 6 characters from a string in IF Then statement

    I wonder if anyone can help -

    I've put together a bit of code that does two actions, but I'm trying to add another to the IF Then code, but this bit keeps erroring out. I'm a novice with VBA so I'm not sure where I've gone wrong...

    Here's the code that works:
    Please Login or Register  to view this content.
    What I also want it to do is to return the last 6 characters from col C, but only in rows where there's data in that column.

    This is the code I added underneath the last If statement
    Please Login or Register  to view this content.
    It doesn't error out when I save the VBA, but when I go to run the code, it gives me a runtime error code 424 "Object required" and the debug button then highlights my last line of code

    I suspect it might be something simple, but I don't have the experience to know what.

    Or could it be because I'm doing a type of circular reference?

    What am I doing wrong??

    I look forward to any help with the correct line of code to add.

    Kindest regards
    Mike

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,510

    Re: extract last 6 characters from a string in IF Then statement

    Please Login or Register  to view this content.
    You do not have a variable "cell" declared. You probably intend for this to be
    Please Login or Register  to view this content.
    It would be been quicker to diagnose with Option Explicit, and you have seen an error at compile time. I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bugs and runtime errors.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Re: extract last 6 characters from a string in IF Then statement

    Hi Jeff, thanks for your quick response. that works fine. If I wanted to enter the previous working day's date instead, what coding would I need?

    Unfortunately I'm a novice with VBA so I'm unfamiliar with what you are recommending.

    I have a book on VBA but as I run the family business I don't have the time to sit down for long spells in the office to study and practice...

    Kind regards

  4. #4
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Re: extract last 6 characters from a string in IF Then statement

    Hi Jeff, DOH! - I just realised my original thread was to do with removing certain letters.

    In that same bit of coding that i originally posted there's a line that enters today's date - I need to change that to enter yesterday's date - should I open a new thread?

    Kind regards
    Mike

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: extract last 6 characters from a string in IF Then statement

    Try
    If .Value <> "" Then .Offset(, -2) = .Offset(, -2) & "=Today()-1"

  6. #6
    Registered User
    Join Date
    11-23-2010
    Location
    Leicester, England
    MS-Off Ver
    Excel 2021 Pro Plus
    Posts
    87

    Re: extract last 6 characters from a string in IF Then statement

    Hi Nigelog, thanks for the response. Works perfectly, thanks.
    I've got some more coding that I need help correcting, but I'll close this thread and start a new one, as strictly speaking its a different topic.
    Kindest regards
    Mike

+ 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 characters from a string
    By oneyejack77 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-06-2018, 07:45 AM
  2. Extract string between two characters
    By Alma in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-28-2016, 10:49 AM
  3. [SOLVED] extract string between two characters
    By JackSmith123 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-17-2015, 12:15 PM
  4. [SOLVED] Extract String from between 2 same characters
    By slamdunka in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2014, 09:37 PM
  5. [SOLVED] Extract left characters from string with exception of 2 right characters
    By sweetkel23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2012, 10:45 PM
  6. [SOLVED] Extract 1-2 characters from a string
    By sweetkel23 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-14-2012, 07:53 PM
  7. EXTRACT all characters from a string
    By Blake 7 in forum Excel General
    Replies: 2
    Last Post: 03-11-2011, 07:06 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