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

I'm looking for a macro that will take the last used cell with a value
in column A and E. Combine the two values and rename the active sheet.
Colum A is formatted for text. Colum E is formatted for the date and
time.( m-d-yy h-mmAM/PM;@")

Example:

A E
Cedarhurst 8-3-07 9-00AM

Should rename the active sheet (Cedarhurst 8-3-07 9-00AM)



Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
TWR TWR is offline
external usenet poster
 
Posts: 30
Default Rename active sheet

Try this. It's not very graceful, but it works.
Private Sub RenameWS()
Dim sTemp1 As String
Dim sTemp2 As String

With ActiveSheet
Range("A" & CStr(.Rows.Count)).Select
Selection.End(xlUp).Select
sTemp1 = Selection.Text
Range("E" & CStr(.Rows.Count)).Select
Selection.End(xlUp).Select
sTemp2 = Selection.Text
' Can't have the following characters : / \ ? * [ or ]
' Just in case there are slashes in the date
sTemp2 = Replace$(sTemp2, "/", "-")
' Can't have a colon either so replace it with a dot or something else
sTemp2 = Replace$(sTemp2, ":", ".")
.Name = sTemp1 & " " & sTemp2
End With
End Sub


"Little Penny" wrote:

I'm looking for a macro that will take the last used cell with a value
in column A and E. Combine the two values and rename the active sheet.
Colum A is formatted for text. Colum E is formatted for the date and
time.( m-d-yy h-mmAM/PM;@")

Example:

A E
Cedarhurst 8-3-07 9-00AM

Should rename the active sheet (Cedarhurst 8-3-07 9-00AM)



Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Rename active sheet

On Jan 6, 12:57 am, TWR wrote:
Try this. It's not very graceful, but it works.
Private Sub RenameWS()
Dim sTemp1 As String
Dim sTemp2 As String

With ActiveSheet
Range("A" & CStr(.Rows.Count)).Select
Selection.End(xlUp).Select
sTemp1 = Selection.Text
Range("E" & CStr(.Rows.Count)).Select
Selection.End(xlUp).Select
sTemp2 = Selection.Text
' Can't have the following characters : / \ ? * [ or ]
' Just in case there are slashes in the date
sTemp2 = Replace$(sTemp2, "/", "-")
' Can't have a colon either so replace it with a dot or something else
sTemp2 = Replace$(sTemp2, ":", ".")
.Name = sTemp1 & " " & sTemp2
End With
End Sub

"Little Penny" wrote:
I'm looking for a macro that will take the last used cell with a value
in column A and E. Combine the two values and rename the active sheet.
Colum A is formatted for text. Colum E is formatted for the date and
time.( m-d-yy h-mmAM/PM;@")


Example:


A E
Cedarhurst 8-3-07 9-00AM


Should rename the active sheet (Cedarhurst 8-3-07 9-00AM)


Thanks


Here's something more compact:

Sub SheetRename()
Dim aPart As String, ePart As String, shtName As String

Range("A1").EntireColumn.Cells(Rows.Count, 1).Select
Selection.End(xlUp).Select
aPart = Selection
ePart = Selection.Offset(0, 4)
shtName = aPart & " " & Format(ePart, "m-d-yy h-mmAM/PM")
ActiveSheet.Name = shtName

End Sub


SteveM
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Rename active sheet

Here's something more compact:

Sub SheetRename()
Dim aPart As String, ePart As String, shtName As String

Range("A1").EntireColumn.Cells(Rows.Count, 1).Select
Selection.End(xlUp).Select
aPart = Selection
ePart = Selection.Offset(0, 4)
shtName = aPart & " " & Format(ePart, "m-d-yy h-mmAM/PM")
ActiveSheet.Name = shtName

End Sub


If compact is your goal, what about this for the body of your SheetRename
subroutine?

Dim R As Range
Set R = ActiveSheet.Cells(Rows.Count, 1).End(xlUp)
R.Parent.Name = R.Value & Format(R.Offset(0, 4).Value, " m-d-yy h-mmAM/PM")

By the way, I used R.Parent.Name to keep the last statement from
word-wrapping in newsreaders... it should be replaced by ActiveSheet.Name
for clarity.

Rick

  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Rename active sheet

On Jan 6, 6:49 am, "Nigel" wrote:
Doesn't this assume that the last row in A and E are the same? The OP asked
for "last used cell with a value
in column A and E", which I read as - could be different?

See my solution that takes both value separately, however I should have used
the format function which would have been better!

--

Regards,
Nigel


"Rick Rothstein (MVP - VB)" wrote in
. ..

Here's something more compact:


Sub SheetRename()
Dim aPart As String, ePart As String, shtName As String


Range("A1").EntireColumn.Cells(Rows.Count, 1).Select
Selection.End(xlUp).Select
aPart = Selection
ePart = Selection.Offset(0, 4)
shtName = aPart & " " & Format(ePart, "m-d-yy h-mmAM/PM")
ActiveSheet.Name= shtName


End Sub


If compact is your goal, what about this for the body of your SheetRename
subroutine?


Dim R As Range
Set R = ActiveSheet.Cells(Rows.Count, 1).End(xlUp)
R.Parent.Name= R.Value & Format(R.Offset(0, 4).Value, " m-d-yy
h-mmAM/PM")


By the way, I used R.Parent.Nameto keep the last statement from
word-wrapping in newsreaders... it should be replaced by ActiveSheet.Name
for clarity.


Rick


Attn: Rick Rothstein and his solution.

Touche' on "compactness"

SteveM

P.S. And to think that I thought that it was the "C" guys who were
like that :)
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Rename active sheet

Sub Rename()
With ActiveSheet
.Name = .Cells(.Rows.Count, "A").End(xlUp) & _
Replace(Replace(.Cells(.Rows.Count, "E").End(xlUp), "/", "-"), ":", "-")
End With
End Sub


--

Regards,
Nigel




"Little Penny" wrote in message
...
I'm looking for a macro that will take the last used cell with a value
in column A and E. Combine the two values and rename the active sheet.
Colum A is formatted for text. Colum E is formatted for the date and
time.( m-d-yy h-mmAM/PM;@")

Example:

A E
Cedarhurst 8-3-07 9-00AM

Should rename the active sheet (Cedarhurst 8-3-07 9-00AM)



Thanks


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
Rename active sheet with current file name [email protected] Excel Programming 5 July 11th 06 11:29 AM
using VBA to rename active sheet Papa Jonah Excel Programming 5 October 22nd 04 02:38 PM
Rename active sheet lumaduc Excel Programming 1 June 3rd 04 08:46 PM
Rename active sheet Ginny[_2_] Excel Programming 2 January 9th 04 10:59 PM
Rename Active Sheet Jason[_25_] Excel Programming 2 September 21st 03 02:03 AM


All times are GMT +1. The time now is 10:59 AM.

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

About Us

"It's about Microsoft Excel"