LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Adding sheets and copying data problem

Ok, I thought since the text was in the All Records sheet in lower case, I
had to have it in lower case in the code. So even though the text is in
quotes, it still doesn't matter. I understand now, thanks for clarifying
that for m.

"Tom Ogilvy" wrote:

what line is highlighted when you get that error?

recall that before I posted that code, it had run successfully for me
(albeit with Book1, Tapes, RED and BLUE instead of VISACard err GESACard etc.
)

in addition, this needs to be corrected:

If UCase(Trim(cell.Value)) = "4-$" And _
UCase(Trim(cell.Offset( _
0, 1).Value)) = "Gesa CC" Then

should be

If UCase(Trim(cell.Value)) = "4-$" And _
UCase(Trim(cell.Offset( _
0, 1).Value)) = "GESA CC" Then

since the Ucase command takes the value in cell and makes it all uppercase
for the comparison.

--
Regards,
Tom Ogilvy




"SITCFanTN" wrote:

Thanks, that makes a world of sense to me. Now my sheets are being added
properly, but the copy and paste isn't taking place. The actual text is col B
of the copy from sheet is "Gesa CC" so I have that in quotes. The error I'm
getting is 1004 Applicatoin-defined or object definred error. I read about it
but truly don't undersand what it is trying to tell me. Do you have an
insight into this run time error code?

here is the new code that I'm using:

Call AddSheets
Call CopyData


End Sub
Sub AddSheets()

Dim NewSheets As Variant
Dim i As Long

NewSheets = Array("Confirm", "GESVCard", "GESACard", "GESACheck", "All
Matches", "All No Matches")
For i = UBound(NewSheets) To LBound(NewSheets) Step -1
Sheets.Add after:=Sheets(1)
ActiveSheet.Name = NewSheets(i)
Next i

End Sub

Sub CopyData()
Dim rng As Range, cell As Range
Dim i As Long, sh As Worksheet
With Worksheets("All Records")
Set rng = .Range(.Cells(1, 1), _
.Cells(Rows.Count, 1).End(xlUp))
End With
i = 1

Set sh = Worksheets("GESACard")
For Each cell In rng
If UCase(Trim(cell.Value)) = "4-$" And _
UCase(Trim(cell.Offset( _
0, 1).Value)) = "Gesa CC" Then
cell.EntireRow.Copy sh.Cells(i, 1)
i = i + 1
End If
Next
End Sub

"Tom Ogilvy" wrote:

the problem is that you have duplicate names in your array. So it create the
4th sheet, but can't rename it and it dies at that point.

Sub AllRecordsSortMacros()

Call AddSheets
Call CopyData


End Sub
Sub AddSheets()

Dim NewSheets As Variant
Dim i As Long

' change he

NewSheets = Array("Confirm", "GESV CC", "GESA CC", "XXXX CC", "All
Matches", "All No Matches")
For i = UBound(NewSheets) To LBound(NewSheets) Step -1
Sheets.Add after:=Sheets(1)
ActiveSheet.Name = NewSheets(i)
Next i

End Sub

Sub CopyData()
Dim rng As Range, cell As Range
Dim i As Long, sh As Worksheet
With Worksheets("All Records")
Set rng = .Range(.Cells(1, 1), _
.Cells(Rows.Count, 1).End(xlUp))
End With
i = 1

' change he

Set sh = Worksheets("GESA CC")
For Each cell In rng
If UCase(Trim(cell.Value)) = "4-$" And _
UCase(Trim(cell.Offset( _
0, 1).Value)) = "GESA CC" Then
cell.EntireRow.Copy sh.Cells(i, 1)
i = i + 1
End If
Next
End Sub

--
Regrds,
Tom Ogilvy

"SITCFanTN" wrote:

I'm trying to use this code to add new sheets to a workbook and copy
information from sheet 1 "All Records" to sheet titled "GESA CC" based on
"4-$" in Col A and "GESA CC" in Col B.

The issues I"m having is for some reason only 3 page are being created then
a generic Sheet 4? Not at all sure why that is happening. Then the sort,
copy and paste is not working. Any help you can provide is certainly
appreciated. Thank you.



Sub AllRecordsSortMacros()

Call AddSheets
Call CopyData


End Sub
Sub AddSheets()

Dim NewSheets As Variant
Dim i As Long

NewSheets = Array("Confirm", "GESV CC", "GESA CC", "GESA CC", "All
Matches", "All No Matches")
For i = UBound(NewSheets) To LBound(NewSheets) Step -1
Sheets.Add after:=Sheets(1)
ActiveSheet.Name = NewSheets(i)
Next i

End Sub

Sub CopyData()
Dim rng As Range, cell As Range
Dim i As Long, sh As Worksheet
With Worksheets("All Records")
Set rng = .Range(.Cells(1, 1), _
.Cells(Rows.Count, 1).End(xlUp))
End With
i = 1
Set sh = Worksheets("All Records")
For Each cell In rng
If UCase(Trim(cell.Value)) = "4-$" And _
UCase(Trim(cell.Offset( _
0, 1).Value)) = "GESA CC" Then
cell.EntireRow.Copy sh.Cells(i, 1)
i = i + 1
End If
Next
End Sub



 
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
Tough problem adding cells from different sheets, in random order Darcy Excel Worksheet Functions 4 January 8th 09 09:41 PM
Problem with copying sheets Salut Excel Discussion (Misc queries) 0 July 11th 07 08:26 PM
Excel 2000 problem copying drawingobjects between sheets SiriS Excel Discussion (Misc queries) 0 February 8th 06 10:31 AM
Problem copying sheets ZipCurs Excel Programming 3 January 11th 06 12:26 PM
Problem copying range and pasting to multiple sheets Murphy Excel Programming 1 October 9th 03 07:13 PM


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