Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Cell value consistency/macro problem.

I am using the macro below to make a new sheet from a template, and then
rename said sheet(s) from a "selected" list (read highlighted). This worked
great, until I decided that I wanted the selected cells to have data from a
reference. Now the macro only makes a duplicate of my template and renames it
with a (2) after it.

Those who use the workbook tend to change the order of the selected cells,
which breaks a summary sheet. To avoid this, the selectable cell's data is
pulled from the summary sheet's same cells in order to try to keep the needed
consistency.

Are there any solutions to my problem? (Also while I am thinking about it,
is there any way to use this macro with numbers and dates?)

Thanks,

-- Alden

Sub TabsFromList()
'David McRitchie based on previous code in sheets.htm
Application.ScreenUpdating = False
Dim cell As Range
Dim newName As String, xx As String
Err.Description = ""
On Error Resume Next
'--cells with numbers, including dates, will be ignored,
For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
'Sheets.Add after:=Sheets(Sheets.Count)

Worksheets("Template").Copy after:=Worksheets(Worksheets.Count)

If Err.Description < "" Then Exit Sub
Err.Description = ""
newName = cell.Text
ActiveSheet.Name = newName
If Err.Description < "" Then
'--failed to rename, probably sheetname already exists...
xx = MsgBox("Failed to rename inserted worksheet " & _
vbLf & _
ActiveSheet.Name & " to " & newName & vbLf & _
Err.Number & " " & Err.Description, vbOKCancel, _
"Failed to Rename Worksheet, it will be deleted:")
'--eliminate already created sheet that failed to be renamed...
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
'--check for immediate cancellation...
If xx = vbCancel Then Exit Sub
Err.Description = ""
End If
Next cell
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Cell value consistency/macro problem.

Hi Alden,

I tested your code and basically it works OK. However, could you post the
formula that you are using for the cell together with the returned result
because I only used a simple formula of =B1+C1 which both contained text.
Also not sure this will help but you could try using cell.value in lieu of
cell.text.

Next question on using numvbers and dates. The following sample code might
help.

Sub Format_Date()

Dim newname As String
Dim myDate As Date

myDate = Date 'Assign Current date to myDate

'Create string from date and concatenate with text
'Use any valid number/date format between double quotes
newname = "MySheet " & Format(myDate, "dd mmm yy")

MsgBox newname


End Sub


--
Regards,

OssieMac


"Alden" wrote:

I am using the macro below to make a new sheet from a template, and then
rename said sheet(s) from a "selected" list (read highlighted). This worked
great, until I decided that I wanted the selected cells to have data from a
reference. Now the macro only makes a duplicate of my template and renames it
with a (2) after it.

Those who use the workbook tend to change the order of the selected cells,
which breaks a summary sheet. To avoid this, the selectable cell's data is
pulled from the summary sheet's same cells in order to try to keep the needed
consistency.

Are there any solutions to my problem? (Also while I am thinking about it,
is there any way to use this macro with numbers and dates?)

Thanks,

-- Alden

Sub TabsFromList()
'David McRitchie based on previous code in sheets.htm
Application.ScreenUpdating = False
Dim cell As Range
Dim newName As String, xx As String
Err.Description = ""
On Error Resume Next
'--cells with numbers, including dates, will be ignored,
For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
'Sheets.Add after:=Sheets(Sheets.Count)

Worksheets("Template").Copy after:=Worksheets(Worksheets.Count)

If Err.Description < "" Then Exit Sub
Err.Description = ""
newName = cell.Text
ActiveSheet.Name = newName
If Err.Description < "" Then
'--failed to rename, probably sheetname already exists...
xx = MsgBox("Failed to rename inserted worksheet " & _
vbLf & _
ActiveSheet.Name & " to " & newName & vbLf & _
Err.Number & " " & Err.Description, vbOKCancel, _
"Failed to Rename Worksheet, it will be deleted:")
'--eliminate already created sheet that failed to be renamed...
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
'--check for immediate cancellation...
If xx = vbCancel Then Exit Sub
Err.Description = ""
End If
Next cell
Application.ScreenUpdating = True
End Sub

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
Insert a new line, without destroying the consistency of the formu HPH Excel Worksheet Functions 6 May 28th 09 11:08 AM
Cell value consistency for all sheets/Macro problem. Alden Excel Programming 0 November 25th 07 04:05 PM
Problem with cell references in my macro Still Learning Excel Programming 1 August 8th 06 01:56 AM
Improve consistency in how Excel and Word 2003 close. Florence Moosengale Excel Discussion (Misc queries) 5 November 30th 05 12:25 AM
how can I change the size of each cell consistency? Matthew Louden Excel Programming 1 October 17th 03 03:13 AM


All times are GMT +1. The time now is 05:04 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"