LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying ranges from one sheet to another

Hi All,

I have earlier posted this question but I think my earlier message wa
not cler, so I am re-posting this again.

I need some help with a problem regarding copying of a range from on
worksheet to another. Although I already have a code, I am getting som
errors, of which I want to ask advise from anyone, as I am not a VB/VB
programmer.

Here is what I would like to do: I have two worksheets, Sheet1 an
Sheet2, with Sheet1 containing the data that will be copied and sheet
as the target sheet.

My Sheet1 looks something like this:

A B C D E F
1 1 1 2 2 3 3
2 1 1 2 2 3 3
3 1 1 2 2 3 3
4 1 1 2 2 3 3
5 1 1 2 2 3 3

And my Sheet2 will originally look like this:

A B C D E F
1 3
2 5
3 1
4
5

When I execute my script, Sheet2 will look something like this:

A B C D E F G
1 3 2 2 3 3 1 1
2 5 2 2 3 3 1 1
3 1 2 2 3 3 1 1
4 * 2 2 3 3 1 1
5 * 2 2 3 3 1 1

* signifies space for presentation purposes

Here is my code:

Code
-------------------

Public Sub CopyThere()

Dim tmpColCtr, targetCol As Integer
Dim rrow As Range
Dim tempSheet, mainSheet As String

tempSheet = "Sheet2"
mainSheet = "Sheet1"
tmpColCtr = 3

With Worksheets(tempSheet)
For Each rrow In .Range("A:A")
If rrow.Value < "" Then
targetCol = rrow.Value
MsgBox "Column value in row is " & targetCol
Sheets(mainSheet).Range(Cells(1, targetCol), Cells(5, (targetCol + 1))).Copy _
Destination:=Sheets(tempSheet).Range(Cells(1, tmpColCtr))
tmpColCtr = tmpColCtr + 2

Else
Exit For
End If

Next rrow
End With

MsgBox "Copying of data completed!"

End Sub

-------------------


When I execute this code, using the worksheet data I have above, I a
getting the error "Run-time error '1004': Application-defined o
object-defined error".

Am I missing something on my declarations, or using th
methods/properties incorrectly? Please help! :(

Thanks in advance for your help!
Sinobat

--
Message posted from http://www.ExcelForum.com

 
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
help with copying multiple ranges and paste it on a work sheet based on conditions prakash Excel Discussion (Misc queries) 0 November 30th 06 10:18 AM
Copying ranges from one sheet to another Sinobato[_9_] Excel Programming 0 July 29th 04 03:14 PM
selectively copying ranges from one sheet to second sheet JPTIII Excel Programming 1 December 5th 03 08:02 PM
copying ranges etc chick-racer[_43_] Excel Programming 0 November 27th 03 02:33 PM
Copying ranges brym Excel Programming 8 July 19th 03 04:27 PM


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