Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default Need Help With Macro to set a value in new sheets

Hey everybody.

I am using a variant of Dave Petersen's macro code to create a new sheet and
rename that sheet based on a list of values in Sheet_2. Here is what I have
so far:

Sub CreateNameSheets()
' by Dave Peterson
' List sheetnames required in col C in a sheet: Sheet_2
' Sub will copy sheets based on the sheet named as: Sheet1
' and name the sheets accordingly

Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim myCell As Range
Dim ListRng2 As Range
Dim myCell2 As Range

Set TemplateWks = Worksheets("Sheet1")
Set ListWks = Worksheets("Sheet_2")
With ListWks
Set ListRng = .Range("C2", .Cells(.Rows.Count, "C").End(xlUp))
Set ListRng2 = .Range("B2", .Cells(.Rows.Count, "B").End(x1Up))
End With

For Each myCell In ListRng.Cells
TemplateWks.Copy After:=Worksheets(Worksheets.Count)
On Error Resume Next
With ActiveSheet
..Name = myCell.Value
..Range("B2").Value = myCell.Value
End With
If Err.Number = 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next myCell

End Sub

I need to assign Cell C3 on the newly copied sheet the value that is found
in the list on sheet "Sheet_2", column B, starting with B2. And I am stuck.
I don't know how to make it happen. I can copy "Sheet1" and rename the copy
with out a problem. I can even change the value of Cell B2 to match the new
sheet name of the copy. But I also need to change Cell C3 of the copy to
match an ID# that is found in Column B of "Sheet_2".

Help please. Thank you. :)

--
Nothing in life is ever easy - just get used to that fact.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Need Help With Macro to set a value in new sheets

Change this section:
..Range("B2").Value = myCell.Value


To this:
..Range("B2").Value = myCell.Value
..Range("C3").Value = myCell.Offset(0,-1).Value

This code says to look one column to the left of myCell (which is back on
Sheet_2).
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"KennyD" wrote:

Hey everybody.

I am using a variant of Dave Petersen's macro code to create a new sheet and
rename that sheet based on a list of values in Sheet_2. Here is what I have
so far:

Sub CreateNameSheets()
' by Dave Peterson
' List sheetnames required in col C in a sheet: Sheet_2
' Sub will copy sheets based on the sheet named as: Sheet1
' and name the sheets accordingly

Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim myCell As Range
Dim ListRng2 As Range
Dim myCell2 As Range

Set TemplateWks = Worksheets("Sheet1")
Set ListWks = Worksheets("Sheet_2")
With ListWks
Set ListRng = .Range("C2", .Cells(.Rows.Count, "C").End(xlUp))
Set ListRng2 = .Range("B2", .Cells(.Rows.Count, "B").End(x1Up))
End With

For Each myCell In ListRng.Cells
TemplateWks.Copy After:=Worksheets(Worksheets.Count)
On Error Resume Next
With ActiveSheet
.Name = myCell.Value
.Range("B2").Value = myCell.Value
End With
If Err.Number = 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next myCell

End Sub

I need to assign Cell C3 on the newly copied sheet the value that is found
in the list on sheet "Sheet_2", column B, starting with B2. And I am stuck.
I don't know how to make it happen. I can copy "Sheet1" and rename the copy
with out a problem. I can even change the value of Cell B2 to match the new
sheet name of the copy. But I also need to change Cell C3 of the copy to
match an ID# that is found in Column B of "Sheet_2".

Help please. Thank you. :)

--
Nothing in life is ever easy - just get used to that fact.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default Need Help With Macro to set a value in new sheets

Worked like a charm. Now on to my next macro. Creating a summary sheet based
on the new sheets that were created. Any thoughts on this? Thanks.

--
Nothing in life is ever easy - just get used to that fact.


"Luke M" wrote:

Change this section:
.Range("B2").Value = myCell.Value


To this:
.Range("B2").Value = myCell.Value
.Range("C3").Value = myCell.Offset(0,-1).Value

This code says to look one column to the left of myCell (which is back on
Sheet_2).
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"KennyD" wrote:

Hey everybody.

I am using a variant of Dave Petersen's macro code to create a new sheet and
rename that sheet based on a list of values in Sheet_2. Here is what I have
so far:

Sub CreateNameSheets()
' by Dave Peterson
' List sheetnames required in col C in a sheet: Sheet_2
' Sub will copy sheets based on the sheet named as: Sheet1
' and name the sheets accordingly

Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim myCell As Range
Dim ListRng2 As Range
Dim myCell2 As Range

Set TemplateWks = Worksheets("Sheet1")
Set ListWks = Worksheets("Sheet_2")
With ListWks
Set ListRng = .Range("C2", .Cells(.Rows.Count, "C").End(xlUp))
Set ListRng2 = .Range("B2", .Cells(.Rows.Count, "B").End(x1Up))
End With

For Each myCell In ListRng.Cells
TemplateWks.Copy After:=Worksheets(Worksheets.Count)
On Error Resume Next
With ActiveSheet
.Name = myCell.Value
.Range("B2").Value = myCell.Value
End With
If Err.Number = 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next myCell

End Sub

I need to assign Cell C3 on the newly copied sheet the value that is found
in the list on sheet "Sheet_2", column B, starting with B2. And I am stuck.
I don't know how to make it happen. I can copy "Sheet1" and rename the copy
with out a problem. I can even change the value of Cell B2 to match the new
sheet name of the copy. But I also need to change Cell C3 of the copy to
match an ID# that is found in Column B of "Sheet_2".

Help please. Thank you. :)

--
Nothing in life is ever easy - just get used to that fact.

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
Using the same macro on different sheets Beverly Darvill[_2_] Excel Worksheet Functions 7 August 21st 08 06:26 PM
macro for same value in 2 different sheets sharmashanu Excel Discussion (Misc queries) 1 March 15th 07 03:26 AM
Add sheets using macro Heine Excel Worksheet Functions 11 November 3rd 06 02:06 PM
macro for new sheets Raza Excel Worksheet Functions 2 November 8th 05 06:10 PM
macro/new sheets daolb Excel Discussion (Misc queries) 5 June 29th 05 10:59 AM


All times are GMT +1. The time now is 09:23 AM.

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"