• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Get Part of Work Sheet Name

Junarkar

Member
Hi,

I am trying to get part of active worksheet name by avoiding date part after underscore. I used below code;
Given Sheet Name is Computers_July 15

Range("K2").Value = Left(ActiveSheet.Name, Len(ActiveSheet.Name) - InStr(ActiveSheet.Name, "_") )

And it returned below result - Compute
Where required result is - Computers

The sheet name is dynamic. If the sheet name is short it will take extra characters (for ex. APSS_Jul insted of APSS). If the sheet name is longer I get less characters like the example given above.

How can I correct it.

Thanks in Advance.
 
Your aim and code do not align. Your code should be:
Code:
Range("K2").Value = Left(ActiveSheet.Name, InStr(ActiveSheet.Name, "_") - 1)

Syntax you have written
Code:
Len(ActiveSheet.Name) - InStr(ActiveSheet.Name, "_")
is more useful to take remainder part of the string after "_".
 
Last edited:
Your aim and code do not align. Your code should be:
Code:
Range("K2").Value = Left(ActiveSheet.Name, InStr(ActiveSheet.Name, "_") - 1)

Syntax you have written
Code:
Len(ActiveSheet.Name) - InStr(ActiveSheet.Name, "_")
is more useful to take remainder part of the string after "_".
Thanks alot shrivallabha...
 
Back
Top