Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Rename sheet

I am trying to rename the active sheet with 1st character of firstnam
and 1st character of lastname.

E.g. in cell K2, I have the staff name John A. Doe. I want the curren
active sheet to be rename to JD (i.e. the 1st character of first an
last name respectively.

Tried doing this but it didn't work:

ActiveSheet.Name=CONCATENATE(LEFT(LEFT(K2,FIND(
",K2)-1),1),LEFT(RIGHT(K2,LEN(K2)-FIND("*",SUBSTITUTE(K2,
","*",LEN(K2)-LEN(SUBSTITUTE(K2," ",""))))),1))

Always have error in the "FIND" function. Thanks in advance for you
hel

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Rename sheet

VBA Find is not the same as the FIND() worksheet function.
To use this in VBA we have to put :-
Application.Worksheetfunction.Find(....) - each time.

Here is some simpler VBA code that also checks for a single space :-

'-------------------------------------------
Sub NAME_SHEET()
Dim MyStr As String
Dim C1 As String
Dim C2 As String
'------------------------------
MyStr = Range("K2").Value
C1 = Left(MyStr, 1)
sp1 = InStr(1, MyStr, " ", vbTextCompare) ' 1st. space
sp2 = InStr(sp1 + 1, MyStr, " ", vbTextCompare) '2nd. space
'------------------------------
If sp2 = 0 Then ' no 2nd. space
C2 = Mid(MyStr, sp1 + 1, 1)
Else
C2 = Mid(MyStr, sp2 + 1, 1)
End If
ActiveSheet.Name = C1 & C2
End Sub
'---------------------------------------------

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Rename sheet

AS long as you have XL2000 or above

Dim iPos as long
With ActiveCell
iPos = InStrRev(.Value, " ")
ActiveSheet.Name = Left(.Value, 1) & Mid(.Value, iPos + 1, 1)
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"slc " wrote in message
...
I am trying to rename the active sheet with 1st character of firstname
and 1st character of lastname.

E.g. in cell K2, I have the staff name John A. Doe. I want the current
active sheet to be rename to JD (i.e. the 1st character of first and
last name respectively.

Tried doing this but it didn't work:

ActiveSheet.Name=CONCATENATE(LEFT(LEFT(K2,FIND("
",K2)-1),1),LEFT(RIGHT(K2,LEN(K2)-FIND("*",SUBSTITUTE(K2,"
","*",LEN(K2)-LEN(SUBSTITUTE(K2," ",""))))),1))

Always have error in the "FIND" function. Thanks in advance for your
help


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i rename a sheet if the rename tab is inactive? Nelson Excel Worksheet Functions 1 March 3rd 10 10:28 AM
macro to: Add new sheet, then rename new sheet with todays date Paul Excel Worksheet Functions 3 September 29th 07 03:17 AM
Move data to new sheet - rename sheet based on criteria ? [email protected] Excel Discussion (Misc queries) 7 May 16th 07 10:22 PM
Rename Sheet Linda@VZ Excel Discussion (Misc queries) 1 November 2nd 05 12:43 PM
how do I rename a sheet jonwyn New Users to Excel 2 March 1st 05 08:36 PM


All times are GMT +1. The time now is 02:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"