Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default slecting data???

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default slecting data???

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default slecting data???

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default slecting data???

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
wksCurrent.Cells.Copy
wksNew.Cells.PasteSpecial xlPasteFormats
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default slecting data???

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default slecting data???

I sorry Jim I ment like if I wanted to pull all the DRG, The kkl, ght, and so
on all at once and move them all at once.

Sorry

"Jim Thomlinson" wrote:

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default slecting data???

This code assumes that there is always something in column A of the Rows
being moved. If that is not the case then let me know...

Public Sub MoveAllErrors()
Call MoveErrors("DRG")
Call MoveErrors("ABC")
End Sub

Private Sub MoveErrors(ByVal strToFind As String)
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim rngToPaste As Range
Const SHEETNAME As String = "Errors"

Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If Not rngFound Is Nothing Then
If SheetExists(SHEETNAME, ThisWorkbook) Then
Set wksNew = Sheets(SHEETNAME)
Else
Set wksNew = Worksheets.Add
wksNew.Name = SHEETNAME
wksCurrent.Rows(1).Copy wksNew.Range("A1")
End If
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
Set rngToPaste = wksNew.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
rngToPaste.PasteSpecial xlPasteValues
rngToPaste.PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Cells.Copy
Application.CutCopyMode = False
End If
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Lime" wrote:

I sorry Jim I ment like if I wanted to pull all the DRG, The kkl, ght, and so
on all at once and move them all at once.

Sorry

"Jim Thomlinson" wrote:

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default slecting data???

Thank you Jim, am I correct in saying that I would just change the Call
moveErrors("DRG") to what ever I want to move at once??

"Jim Thomlinson" wrote:

This code assumes that there is always something in column A of the Rows
being moved. If that is not the case then let me know...

Public Sub MoveAllErrors()
Call MoveErrors("DRG")
Call MoveErrors("ABC")
End Sub

Private Sub MoveErrors(ByVal strToFind As String)
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim rngToPaste As Range
Const SHEETNAME As String = "Errors"

Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If Not rngFound Is Nothing Then
If SheetExists(SHEETNAME, ThisWorkbook) Then
Set wksNew = Sheets(SHEETNAME)
Else
Set wksNew = Worksheets.Add
wksNew.Name = SHEETNAME
wksCurrent.Rows(1).Copy wksNew.Range("A1")
End If
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
Set rngToPaste = wksNew.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
rngToPaste.PasteSpecial xlPasteValues
rngToPaste.PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Cells.Copy
Application.CutCopyMode = False
End If
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Lime" wrote:

I sorry Jim I ment like if I wanted to pull all the DRG, The kkl, ght, and so
on all at once and move them all at once.

Sorry

"Jim Thomlinson" wrote:

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default slecting data???

Jim,
What do I need to change to get it to put all the pulls on one sheet
together?

"Lime" wrote:

Thank you Jim, am I correct in saying that I would just change the Call
moveErrors("DRG") to what ever I want to move at once??

"Jim Thomlinson" wrote:

This code assumes that there is always something in column A of the Rows
being moved. If that is not the case then let me know...

Public Sub MoveAllErrors()
Call MoveErrors("DRG")
Call MoveErrors("ABC")
End Sub

Private Sub MoveErrors(ByVal strToFind As String)
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim rngToPaste As Range
Const SHEETNAME As String = "Errors"

Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If Not rngFound Is Nothing Then
If SheetExists(SHEETNAME, ThisWorkbook) Then
Set wksNew = Sheets(SHEETNAME)
Else
Set wksNew = Worksheets.Add
wksNew.Name = SHEETNAME
wksCurrent.Rows(1).Copy wksNew.Range("A1")
End If
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
Set rngToPaste = wksNew.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
rngToPaste.PasteSpecial xlPasteValues
rngToPaste.PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Cells.Copy
Application.CutCopyMode = False
End If
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Lime" wrote:

I sorry Jim I ment like if I wanted to pull all the DRG, The kkl, ght, and so
on all at once and move them all at once.

Sorry

"Jim Thomlinson" wrote:

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default slecting data???

It should put all of the moved items onto one sheet named Errors. It will
break down and overwrite values if Column A is not populated on every row
that is being moved...
--
HTH...

Jim Thomlinson


"Lime" wrote:

Jim,
What do I need to change to get it to put all the pulls on one sheet
together?

"Lime" wrote:

Thank you Jim, am I correct in saying that I would just change the Call
moveErrors("DRG") to what ever I want to move at once??

"Jim Thomlinson" wrote:

This code assumes that there is always something in column A of the Rows
being moved. If that is not the case then let me know...

Public Sub MoveAllErrors()
Call MoveErrors("DRG")
Call MoveErrors("ABC")
End Sub

Private Sub MoveErrors(ByVal strToFind As String)
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim rngToPaste As Range
Const SHEETNAME As String = "Errors"

Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If Not rngFound Is Nothing Then
If SheetExists(SHEETNAME, ThisWorkbook) Then
Set wksNew = Sheets(SHEETNAME)
Else
Set wksNew = Worksheets.Add
wksNew.Name = SHEETNAME
wksCurrent.Rows(1).Copy wksNew.Range("A1")
End If
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
Set rngToPaste = wksNew.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
rngToPaste.PasteSpecial xlPasteValues
rngToPaste.PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Cells.Copy
Application.CutCopyMode = False
End If
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Lime" wrote:

I sorry Jim I ment like if I wanted to pull all the DRG, The kkl, ght, and so
on all at once and move them all at once.

Sorry

"Jim Thomlinson" wrote:

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default slecting data???

The code is not. Debug at second sheetname???

"Jim Thomlinson" wrote:

It should put all of the moved items onto one sheet named Errors. It will
break down and overwrite values if Column A is not populated on every row
that is being moved...
--
HTH...

Jim Thomlinson


"Lime" wrote:

Jim,
What do I need to change to get it to put all the pulls on one sheet
together?

"Lime" wrote:

Thank you Jim, am I correct in saying that I would just change the Call
moveErrors("DRG") to what ever I want to move at once??

"Jim Thomlinson" wrote:

This code assumes that there is always something in column A of the Rows
being moved. If that is not the case then let me know...

Public Sub MoveAllErrors()
Call MoveErrors("DRG")
Call MoveErrors("ABC")
End Sub

Private Sub MoveErrors(ByVal strToFind As String)
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim rngToPaste As Range
Const SHEETNAME As String = "Errors"

Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If Not rngFound Is Nothing Then
If SheetExists(SHEETNAME, ThisWorkbook) Then
Set wksNew = Sheets(SHEETNAME)
Else
Set wksNew = Worksheets.Add
wksNew.Name = SHEETNAME
wksCurrent.Rows(1).Copy wksNew.Range("A1")
End If
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
Set rngToPaste = wksNew.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
rngToPaste.PasteSpecial xlPasteValues
rngToPaste.PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Cells.Copy
Application.CutCopyMode = False
End If
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Lime" wrote:

I sorry Jim I ment like if I wanted to pull all the DRG, The kkl, ght, and so
on all at once and move them all at once.

Sorry

"Jim Thomlinson" wrote:

That last bit of code pasted the formats for the entire sheet. This pastes
the formats for only the effected lines...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
wksNew.Range("A2").PasteSpecial xlPasteFormats
rngAllFound.Delete
wksCurrent.Rows(1).Copy wksNew.Range("A1")
Application.CutCopyMode = False
End If
End Sub

--
HTH...

Jim Thomlinson


"Lime" wrote:

Great that brought it over but not the header or the format. What if I want
to pull a string can I pull at once?

"Jim Thomlinson" wrote:

Give this a try...

Sub MoveErrors()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngFirst As Range
Dim rngFound As Range
Dim rngAllFound As Range
Dim rngToSearch As Range
Dim strToFind As String

strToFind = "DRG"
Set wksCurrent = Sheets("Sheet1")
Set rngToSearch = wksCurrent.Columns("C")
Set rngFound = rngToSearch.Find(What:=strToFind, LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Sorry. Nothing to Move"
Else
Set wksNew = Worksheets.Add
Set rngFirst = rngFound
Set rngAllFound = rngFound.EntireRow
Do
Set rngAllFound = Union(rngAllFound, rngFound.EntireRow)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFirst.Address
rngAllFound.Copy
wksNew.Range("A2").PasteSpecial xlPasteValues
rngAllFound.Delete
Application.CutCopyMode = False
End If
End Sub
--
HTH...

Jim Thomlinson


"Lime" wrote:

if I want to look for only certin data in a column say (Drg) and move the
whole row of data to a new sheet in the workbook an call it " Errors" does
anyone know how to approach?

Thanks,
Lime

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
slecting all entries to appear once ron Excel Worksheet Functions 1 March 21st 09 12:26 PM
slecting all entries to appear once Resi Excel Worksheet Functions 7 March 12th 09 09:53 PM
Increase Your Business By Data Conversion, Data Format and Data EntryServices in India Data Entry India Excel Worksheet Functions 1 March 31st 08 12:51 PM
Data Entry Online, Data Format, Data Conversion and Data EntryServices through Data Entry Outsourcing [email protected] Excel Discussion (Misc queries) 0 March 20th 08 12:45 PM
Slecting worksheets one by one.....possible? Ron[_32_] Excel Programming 2 November 2nd 05 01:07 PM


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