Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Cut instead of Copy

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Cut instead of Copy

Have you tried changing

rngFoundAll.EntireRow.Copy rngDestination

to

rngFoundAll.EntireRow.Cut rngDestination

--
Regards,
Tom Ogilvy


"RigasMinho" wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Cut instead of Copy

Yeah i tried that already and it gives me an error.

I'm able to use the cut on this other code i made but that code is
really hard to understand lol.


Tom Ogilvy wrote:
Have you tried changing

rngFoundAll.EntireRow.Copy rngDestination

to

rngFoundAll.EntireRow.Cut rngDestination

--
Regards,
Tom Ogilvy


"RigasMinho" wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Cut instead of Copy

Yeah i tried that already and it gives me an error.

I'm able to use the cut on this other code i made but that code is
really hard to understand lol.


Tom Ogilvy wrote:
Have you tried changing

rngFoundAll.EntireRow.Copy rngDestination

to

rngFoundAll.EntireRow.Cut rngDestination

--
Regards,
Tom Ogilvy


"RigasMinho" wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cut instead of Copy

How about just using .copy and then delete those original rows?

rngFoundAll.EntireRow.Copy rngDestination
rngfoundall.entirerow.delete




RigasMinho wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Cut instead of Copy

Heheh thought of that too

But at the end i will use that command line if i have too.

but currently i dont want to do it that way.

i guess i'm just bored so i want to try to figure this out.

I also tried putting the cut line inside the loop. That cuts it over
but craps out and asks to be debugged.

Thanks though for your suggestion

Dave Peterson wrote:
How about just using .copy and then delete those original rows?

rngFoundAll.EntireRow.Copy rngDestination
rngfoundall.entirerow.delete




RigasMinho wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If


--

Dave Peterson


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Cut instead of Copy

I didn't examine your code closely enough. To the best of my knowledge, you
can't CUT a discontiguous range. Just to confirm:

From VBA help on the CUT method:

The cut range must be made up of adjacent cells.


--
Regards,
Tom Ogilvy




"RigasMinho" wrote:

Yeah i tried that already and it gives me an error.

I'm able to use the cut on this other code i made but that code is
really hard to understand lol.


Tom Ogilvy wrote:
Have you tried changing

rngFoundAll.EntireRow.Copy rngDestination

to

rngFoundAll.EntireRow.Cut rngDestination

--
Regards,
Tom Ogilvy


"RigasMinho" wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cut instead of Copy

If you're cutting the line, you'll have to change the way your do/loop works.
You'll never find the first occurence again--it's already been moved.

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")

Do
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)

if rngfound is nothing then
exit do
end if

rngfound.entirerow.cut _
destination:=rngdestination

set rngdestination=rngdestination.offset(1,0)
loop

=====
Untested, uncompiled. Watch for typos.




RigasMinho wrote:

Heheh thought of that too

But at the end i will use that command line if i have too.

but currently i dont want to do it that way.

i guess i'm just bored so i want to try to figure this out.

I also tried putting the cut line inside the loop. That cuts it over
but craps out and asks to be debugged.

Thanks though for your suggestion

Dave Peterson wrote:
How about just using .copy and then delete those original rows?

rngFoundAll.EntireRow.Copy rngDestination
rngfoundall.entirerow.delete




RigasMinho wrote:

I have this code here where it finds and copies the entire row where
the search is made.

But instead of copying the entire row is there a way to cut the
information instead?
Let me know thanks

Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String
Dim wksDestination As Worksheet
Dim rngDestination As Range

Set wksDestination = Sheets("Output")
Set rngDestination = wksDestination.Range("A1")
Set wksToSearch = Sheets("Master Questions")
Set rngToSearch = wksToSearch.Columns("E:F")
Set rngFound = rngToSearch.Find(What:="AC", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry. Not found"

Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'rngFoundAll.Copy rngDestination

'rngDestination.Resize(rngFoundAll.Cells.Count).In terior.ColorIndex = 3
rngFoundAll.EntireRow.Copy rngDestination
End If


--

Dave Peterson


--

Dave Peterson
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
A visual basic value copy BUG?? - accounting format has copy problem!! [email protected] Excel Programming 3 June 20th 06 04:42 PM
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM
copy formulas from a contiguous range to a safe place and copy them back later Lucas Budlong Excel Programming 2 February 22nd 06 08:26 PM
EXCEL FILE a copy/a copy/a copy ....filename ve New Users to Excel 1 September 29th 05 09:12 PM
How copy format, font, color and border without copy/paste? Michel[_3_] Excel Programming 1 November 5th 03 04:43 PM


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