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


I want to write a procedure/macro that will decide if n = 1 To 10000
Step 1 Cells(n, "?") .Value on Sheet 1 equal a Cell.Value on Sheet 2:
if TRUE then I want to copy the entire Sheet 1 Row onto consecutive
rows on sheet 2: then I want repeat the procedure for other values on
sheet 1, up to about a total of 100 values. Would anyone like to help?
Sounds challenging to me but might be a piece of cake for you experts.
Any replies, even comments on either my ignorance or nerve for asking
will be appreciated.


--
knowtrump
------------------------------------------------------------------------
knowtrump's Profile: http://www.excelforum.com/member.php...o&userid=19664
View this thread: http://www.excelforum.com/showthread...hreadid=506107

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying Sheet to Sheet

Sub ABC()
dim rng1 as Range, rng2 as Range
Dim cell as Range, rw as Long
With Worksheets("Sheet1")
set rng1 = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With

With Worksheets("Sheet2")
rw = .Cells(rows.count,1).End(xlup).Row + 1
set rng2 = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each cell in rng1
res = Application.Match(cell,rng2,0)
if not iserror(res) then
cell.EntireRow.copy Destination:=rng2.Parent.Cells(rw,1)
rw = rw + 1
end if
Next
End Sub

--
Regards,
Tom Ogilvy


"knowtrump" wrote
in message ...

I want to write a procedure/macro that will decide if n = 1 To 10000
Step 1 Cells(n, "?") .Value on Sheet 1 equal a Cell.Value on Sheet 2:
if TRUE then I want to copy the entire Sheet 1 Row onto consecutive
rows on sheet 2: then I want repeat the procedure for other values on
sheet 1, up to about a total of 100 values. Would anyone like to help?
Sounds challenging to me but might be a piece of cake for you experts.
Any replies, even comments on either my ignorance or nerve for asking
will be appreciated.


--
knowtrump
------------------------------------------------------------------------
knowtrump's Profile:

http://www.excelforum.com/member.php...o&userid=19664
View this thread: http://www.excelforum.com/showthread...hreadid=506107



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying Sheet to Sheet


Tom, Thanks for the help. However, I'm still having problems. First
I haven't quite figured what each line of code or code statement i
doing. My bad I'm sure. Second, when I tried to run the procedure
got a Compile error Variable not defined res=
I tried to Dim res as Range and got Object variable or Withbloc
variable not set
I tried to Dim res as Long and got Run-time error '13': Type mismatch
I'm trying to get everything I can out of Sams, "Teach Yoursel
Microsoft Excel 2000 Programming in 24 Hours." It's slow going and m
smarts aren't yet up to the answer you were nice enough to give me.
Could I prevail upon you a little further

--
knowtrum
-----------------------------------------------------------------------
knowtrump's Profile: http://www.excelforum.com/member.php...fo&userid=1966
View this thread: http://www.excelforum.com/showthread.php?threadid=50610

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying Sheet to Sheet

res should be dimmed as Variant.

application.Match will return either a long or an error value, so you need
to be able to accept either - thus a variant.

Sub ABC()
Dim rng1 As Range, rng2 As Range
Dim cell As Range, rw As Long
Dim res As Variant
With Worksheets("Sheet1")
Set rng1 = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With

With Worksheets("Sheet2")
rw = .Cells(Rows.Count, 1).End(xlUp).Row + 1
Set rng2 = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each cell In rng1
res = Application.Match(cell, rng2, 0)
If Not IsError(res) Then
cell.EntireRow.Copy Destination:=rng2.Parent.Cells(rw, 1)
rw = rw + 1
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"knowtrump" wrote
in message ...

Tom, Thanks for the help. However, I'm still having problems. First,
I haven't quite figured what each line of code or code statement is
doing. My bad I'm sure. Second, when I tried to run the procedure I
got a Compile error Variable not defined res=
I tried to Dim res as Range and got Object variable or Withblock
variable not set
I tried to Dim res as Long and got Run-time error '13': Type mismatch
I'm trying to get everything I can out of Sams, "Teach Yourself
Microsoft Excel 2000 Programming in 24 Hours." It's slow going and my
smarts aren't yet up to the answer you were nice enough to give me.
Could I prevail upon you a little further?


--
knowtrump
------------------------------------------------------------------------
knowtrump's Profile:

http://www.excelforum.com/member.php...o&userid=19664
View this thread: http://www.excelforum.com/showthread...hreadid=506107



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 help Taking alot data from one sheet (if not blank) and copying toa list on another sheet. Alex Zuniga Excel Worksheet Functions 1 November 25th 09 11:54 PM
Copying the repeated data of the previous sheet to the next sheet Sasikiran Excel Discussion (Misc queries) 1 September 25th 07 03:18 PM
Dynamic column chart - copying from Sheet to Sheet. Marko Pinteric Excel Discussion (Misc queries) 1 April 10th 06 12:57 PM
Copying cells from on sheet to another sheet (via sheet module) CRayF Excel Programming 6 September 20th 05 08:58 PM
2 questions, copying data from sheet to sheet and assigning macro Boris Excel Worksheet Functions 0 December 16th 04 06:11 PM


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