Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need this code snippet to work in the insert sheet code below.
worksheets.Add Befo=worksheets("End") Also, if I can insert a "Begin" sheet to indicate when to begin inserting sheets, it would work wonders for me. Thanx.! Here's my insert sheet code. Sub Cop_RowS_To_Sheets() 'copy rows to worksheets based on value in column A 'assume the worksheet name to paste to is the value in Col A Dim CurrentCell As Range Dim SourceRow As Range Dim Targetsht As Worksheet Dim TargetRow As Long Dim CurrentCellValue As String 'start with cell A2 on Sheet1 Set CurrentCell = Worksheets("ALL ERRORS").Cells(2, 1) 'row 2 column 1 Do While Not IsEmpty(CurrentCell) CurrentCellValue = CurrentCell.Value Set SourceRow = CurrentCell.EntireRow 'Check if worksheet exists On Error Resume Next Testwksht = Worksheets(CurrentCellValue).Name If Err.Number = 0 Then 'MsgBox CurrentCellValue & " worksheet Exists" Else MsgBox "Adding a new worksheet for " & CurrentCellValue Worksheets.Add.Name = CurrentCellValue End If On Error GoTo 0 'reset on error to trap errors again Set Targetsht = ActiveWorkbook.Worksheets(CurrentCellValue) 'note: using CurrentCell.value gave me an error if the value was numeric ' Find next blank row in Targetsht - check using Column A TargetRow = Targetsht.Cells(Rows.Count, 1).End(xlUp).Row + 1 SourceRow.Copy Destination:=Targetsht.Cells(TargetRow, 1) 'do the next cell Set CurrentCell = CurrentCell.Offset(1, 0) Loop End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Worksheets.Add(befo=Worksheets(Worksheets.Count )).Name = "MySheet"
|
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() stevebriz wrote: Worksheets.Add(befo=Worksheets(Worksheets.Count )).Name = "MySheet" I believe this will work however, is there a simpler way to insert this one into my code? I am getting thrown off with fitting it into my code and referring to my sheet names. The names of my sheets are "start" & "end". Any sheet added will need to go in between these two. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() J.W. Aldridge wrote: stevebriz wrote: Worksheets.Add(befo=Worksheets(Worksheets.Count )).Name = "MySheet" I believe this will work however, is there a simpler way to insert this one into my code? I am getting thrown off with fitting it into my code and referring to my sheet names. The names of my sheets are "start" & "end". Any sheet added will need to go in between these two. Not sure I understood you correctly but here goes.... If the "start sheet is before the "end "sheet then the below will work- then you can use: Worksheets.Add(befo=Sheets("end")).Name = "MySheet1" but you need to be careful not to try and add a sheet with the same name or you will get an error. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() worked like a charm!!!! Thanx!!!! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
code to insert add'l code ??? | Excel Programming | |||
Inserting a row in sheet A should Insert a row in sheet B, removing a row in Sheet A should remove the corresponding row in sheet B | Excel Programming | |||
how to programmingly insert a new row in excel sheet?(using VB code) | Excel Programming | |||
VBA code to insert images in excel sheet | Excel Programming | |||
How do I insert/update VBA code into a sheet? (using a CLS file?) | Excel Programming |