#1   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Capture

Every time Column I has 04 or 05 in a row, I would like to cut that
entire row Columns A:AH, create a new worksheet named 0405 , and paste
those cut rows into the new worksheet, so that the rows do not overlap.

Here is what I have so far. Any help would be appreciated.

Sub Capture0405()

Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Capture


Sub Capture0405()

set oldsht = activesheet
Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"

NewRow = 1
with oldsht
OldRow = 1
do while .Range("I" & OldRow) < ""
if .Range("I" & OldRow) = 4 or _
.Range("I" & OldRow) = 5 then
.Range("A" & OldRow & ":H" & OldRow).copy _
Destination:=NewSht.Range("A" & Newrow)
NewRow = NewRow + 1
end if
OldRow = OldRow + 1
Loop
End Sub


"Sal" wrote:

Every time Column I has 04 or 05 in a row, I would like to cut that
entire row Columns A:AH, create a new worksheet named 0405 , and paste
those cut rows into the new worksheet, so that the rows do not overlap.

Here is what I have so far. Any help would be appreciated.

Sub Capture0405()

Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Capture


Try code like the following. It will create the sheet "0405" if it
doesn't exist.

Sub AAA()

Dim LastRow As Long
Dim RowNdx As Long
Dim SourceWS As Worksheet
Dim DestWS As Worksheet
Dim Dest As Range
Dim DeleteThese As Range
Dim R As Range

Set SourceWS = Worksheets("Sheet1") '<<< Change
On Error Resume Next
Set DestWS = Worksheets("0405")
If DestWS Is Nothing Then
' doesn't exist. create it.
With ThisWorkbook.Worksheets
Set DestWS = .Add(after:=.Item(.Count))
DestWS.Name = "0405"
End With
End If
With DestWS
Set Dest = .Cells(.Rows.Count, "A").End(xlUp)
If Dest.Value < vbNullString Then
Set Dest = Dest(2, 1)
End If
End With
On Error GoTo 0
With SourceWS
LastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
For RowNdx = 1 To LastRow
Set R = .Cells(RowNdx, "i")
Select Case R.Value
Case "04", "05"
If DeleteThese Is Nothing Then
Set DeleteThese = R.EntireRow
Else
Set DeleteThese = _
Application.Union(DeleteThese, R.EntireRow)
End If
R.EntireRow.Copy Destination:=Dest
Set Dest = Dest(2, 1)
Case Else
' do nothing
End Select
Next RowNdx
End With

If Not DeleteThese Is Nothing Then
DeleteThese.Delete
End If

End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 28 May 2009 13:31:01 -0700, Sal
wrote:

Every time Column I has 04 or 05 in a row, I would like to cut that
entire row Columns A:AH, create a new worksheet named 0405 , and paste
those cut rows into the new worksheet, so that the rows do not overlap.

Here is what I have so far. Any help would be appreciated.

Sub Capture0405()

Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Capture

This is great. Thank you for the help.

"Joel" wrote:


Sub Capture0405()

set oldsht = activesheet
Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"

NewRow = 1
with oldsht
OldRow = 1
do while .Range("I" & OldRow) < ""
if .Range("I" & OldRow) = 4 or _
.Range("I" & OldRow) = 5 then
.Range("A" & OldRow & ":H" & OldRow).copy _
Destination:=NewSht.Range("A" & Newrow)
NewRow = NewRow + 1
end if
OldRow = OldRow + 1
Loop
End Sub


"Sal" wrote:

Every time Column I has 04 or 05 in a row, I would like to cut that
entire row Columns A:AH, create a new worksheet named 0405 , and paste
those cut rows into the new worksheet, so that the rows do not overlap.

Here is what I have so far. Any help would be appreciated.

Sub Capture0405()

Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Capture

Wow, I appreciate this very much. The macro works very well. Thank you for
the help.

"Chip Pearson" wrote:


Try code like the following. It will create the sheet "0405" if it
doesn't exist.

Sub AAA()

Dim LastRow As Long
Dim RowNdx As Long
Dim SourceWS As Worksheet
Dim DestWS As Worksheet
Dim Dest As Range
Dim DeleteThese As Range
Dim R As Range

Set SourceWS = Worksheets("Sheet1") '<<< Change
On Error Resume Next
Set DestWS = Worksheets("0405")
If DestWS Is Nothing Then
' doesn't exist. create it.
With ThisWorkbook.Worksheets
Set DestWS = .Add(after:=.Item(.Count))
DestWS.Name = "0405"
End With
End If
With DestWS
Set Dest = .Cells(.Rows.Count, "A").End(xlUp)
If Dest.Value < vbNullString Then
Set Dest = Dest(2, 1)
End If
End With
On Error GoTo 0
With SourceWS
LastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
For RowNdx = 1 To LastRow
Set R = .Cells(RowNdx, "i")
Select Case R.Value
Case "04", "05"
If DeleteThese Is Nothing Then
Set DeleteThese = R.EntireRow
Else
Set DeleteThese = _
Application.Union(DeleteThese, R.EntireRow)
End If
R.EntireRow.Copy Destination:=Dest
Set Dest = Dest(2, 1)
Case Else
' do nothing
End Select
Next RowNdx
End With

If Not DeleteThese Is Nothing Then
DeleteThese.Delete
End If

End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 28 May 2009 13:31:01 -0700, Sal
wrote:

Every time Column I has 04 or 05 in a row, I would like to cut that
entire row Columns A:AH, create a new worksheet named 0405 , and paste
those cut rows into the new worksheet, so that the rows do not overlap.

Here is what I have so far. Any help would be appreciated.

Sub Capture0405()

Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
newsht.Name = "0405"
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
Need VBA to capture who and when xrbbaker Excel Programming 9 December 23rd 08 03:15 PM
Capture user ID... Doolee Excel Discussion (Misc queries) 2 March 24th 08 07:20 PM
Excel screen capture to capture cells and row and column headings jayray Excel Discussion (Misc queries) 5 November 2nd 07 11:01 PM
Up Capture Alex Excel Programming 0 July 26th 04 08:09 PM
Time Capture... Tom Ogilvy Excel Programming 3 November 19th 03 01:25 AM


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