(Yet) Another Sheet Copying Problem

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
177
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
good day to all!

I don't know if its the lack of sleep or what! but can't seems to find the problem
I'm trying to copy all records from sheet (source) to the lastrow of another sheet (target) with the following code

VBA Code:
For iLOOP = 2 To FinalRow
' METHOD 1
    Worksheets("TARGET").Range("A" & TargetLastRow & ":" & TargetLastColumnLetter & TargetLastRow).Value = Worksheets("SOURCE").Range("A" & iLOOP & ":" & LastChar & iLOOP).Value
' METHOD 2
    Worksheets("SOURCE").Range("A" & iLOOP & ":" & LColX00 & iLOOP).Copy Destination:=Worksheets("TARGET").Range("A" & TargetLastRow & ":" & TargetLastColumnLetter & TargetLastRow)
    cTr = cTr + 1
Next

with the following error
(METHOD 1) - Run-time error 1004 - Application-Defined or Object-Defined error
(METHOD 2) - Run-time error 9 - Subscript out of range
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Have you checked the values assigned to all the variables?
Method 1 needs the source and target ranges to be the same size. Cannot verify from the code you posted.
It appears unlikely that you need a loop.
 
Upvote 0
Have you checked the values assigned to all the variables?
Method 1 needs the source and target ranges to be the same size. Cannot verify from the code you posted.
It appears unlikely that you need a loop.
thanks mate, yap size differs from Sheet Source (4582 rows) and Sheet Target (229 rows)
though I manage to solved the my problem with a different solution, I would still love to solve the problem presented. I'll try to upload dummy records for referrence..
 
Upvote 0
up... sample dummy records

00 DUMMY ZERO - II.xlsx
ABCD
1SPECIECOUNTRYSTATUSGENDER
2American flamingoAfghanistanHatchedF
3AlcidsAfghanistanHatchedF
4Amazon kingfisherAfghanistanHatchedF
5AlbatrossesAfghanistanSoldF
6AlbatrossesAfghanistanSoldF
7Accipiter hawksAfghanistanSoldF
8Accipiter hawksAfghanistanSoldF
9American dipperAlbaniaHatchedF
10Accipiter hawksAlbaniaHatchedF
11AlbatrossesAlbaniaSoldF,F
12American flamingoAlgeriaHatchedF,F
13AlbatrossesAlgeriaSoldF,F
14AlbatrossesAlgeriaSoldF,F
15Accipiter hawksAlgeriaSoldF,F
16American dipperAndorraHatchedF,F
17AlcidsAndorraHatchedF,F,F,F
18AlbatrossesAndorraSoldF,F,M,F
19AlbatrossesAndorraHatchedF,M
20Accipiter hawksAndorraSoldF,M
21AlbatrossesAngolaSoldF,M
22Accipiter hawksAngolaSoldF,M
23AlbatrossesAntigua and BarbudaSoldF,M
24AlbatrossesAntigua and BarbudaSoldF,M
25AlbatrossesAntigua and BarbudaSoldF,M
26AlbatrossesAntigua and BarbudaSoldF,M
27AlbatrossesAntigua and BarbudaSoldF,M
28AlbatrossesAntigua and BarbudaSoldF,M
29Accipiter hawksAntigua and BarbudaSoldF,M
30Accipiter hawksAntigua and BarbudaSoldF,M
31Accipiter hawksAntigua and BarbudaSoldM
32Accipiter hawksAntigua and BarbudaSoldM
33Accipiter hawksAntigua and BarbudaSoldM
34AlbatrossesArgentinaSoldM
35AlbatrossesArgentinaSoldM
36Accipiter hawksArgentinaSoldM
37Accipiter hawksArgentinaSoldM
38American dipperArmeniaHatchedM
39American kestrelArmeniaHatchedM
40American white pelicanArmeniaHatchedM
41American white pelicanArmeniaHatchedM
42American white pelicanArmeniaHatchedM
43AlbatrossesArmeniaSoldM
44AlbatrossesArmeniaSoldM
45AlbatrossesArmeniaSoldM
46AlbatrossesArmeniaSoldM
47AlbatrossesArmeniaHatchedM
48AlbatrossesArmeniaSoldM
49AlbatrossesArmeniaSoldM
50AlcidsArmeniaHatchedM
51Accipiter hawksArmeniaSoldM
52Accipiter hawksArmeniaSoldM
53Accipiter hawksArmeniaSoldM
54American dipperAustraliaHatchedM
55American white pelicanAustraliaHatchedM
56Accipiter hawksAustraliaSoldM
57Accipiter hawksAustraliaHatchedM
58American dipperAustriaHatchedM
59American dipperAustriaHatchedM
60American kestrelAustriaHatchedM
61American white pelicanAustriaHatchedM
62American white pelicanAustriaHatchedM
63AlbatrossesAustriaSoldM
64AlbatrossesAustriaSoldM
65AlbatrossesAustriaSoldM
66AlbatrossesAustriaSoldM
67AlbatrossesAustriaSoldM
68AlbatrossesAustriaSoldM
69AlbatrossesAustriaSoldM
70AlbatrossesAustriaSoldM
71Accipiter hawksAustriaSoldM
72Accipiter hawksAustriaSoldM
73Accipiter hawksAustriaSoldM
74Accipiter hawksAustriaSoldM
75American kestrelAzerbaijanHatchedM
76AlbatrossesAzerbaijanSoldM
77American dipperBahamasHatchedM
78American white pelicanBahrainHatchedM
79American dipperBangladeshHatchedM
80AlcidsBangladeshHatchedM
81Accipiter hawksBangladeshHatchedM
82American dipperBarbadosHatchedM
83American kestrelBarbadosSoldM
84American kestrelBarbadosHatchedM
85American white pelicanBarbadosHatchedM
86American white pelicanBarbadosHatchedM
87AlcidsBarbadosHatchedM
88Accipiter hawksBarbadosHatchedM
89AlbatrossesBarbadosSoldM
90AlbatrossesBarbadosSoldM
91AlbatrossesBarbadosSoldM
92Accipiter hawksBarbadosSoldM
93Accipiter hawksBarbadosSoldM
94American dipperBelarusHatchedM
95American white pelicanBelarusHatchedM
96American white pelicanBelarusHatchedM
97American white pelicanBelarusHatchedM
98American white pelicanBelarusHatchedM
99American white pelicanBelarusHatchedM
100AlcidsBelarusHatchedM,F
101Accipiter hawksBelarusHatchedM,F
102AlbatrossesBelarusSoldM,F
103AlbatrossesBelarusSoldM,F
104AlbatrossesBelarusSoldM,F
105Accipiter hawksBelarusSoldM,F
106Accipiter hawksBelarusSoldM,F
107AlbatrossesBelgiumSoldM,F
108AlbatrossesBelgiumSoldM,F
109Accipiter hawksBelgiumSoldM,F
110Accipiter hawksBelgiumSoldM,F
111AlcidsBelizeSoldM,F
112AlbatrossesBelizeSoldM,F
113Accipiter hawksBelizeSoldM,F
114American white pelicanBeninHatchedM,F
115American white pelicanBeninHatchedM,F
116AlcidsBeninHatchedM,F
117Amazon kingfisherBeninSoldM,F
118AlbatrossesBeninSoldM,F
119AlbatrossesBeninSoldM,F
120AlbatrossesBeninSoldM,F
121AlbatrossesBeninSoldM,F
122Accipiter hawksBeninSoldM,M,M
123Accipiter hawksBeninSoldM,M,M
124Accipiter hawksBeninSoldM,M,M
125Amazon kingfisherBhutanSoldM,M,M
126AlbatrossesBoliviaSoldM,M,M
127AlbatrossesBoliviaSoldM,M,M
128AlbatrossesBoliviaSoldM,M,M
129Accipiter hawksBoliviaSoldM,M,M
130Accipiter hawksBoliviaSoldM,M,M
131Accipiter hawksBoliviaSoldM,M,M
132AlbatrossesBosnia and HerzegovinaSoldM,M,M
133AlbatrossesBosnia and HerzegovinaSoldM,M,M
134American kestrelBotswanaHatchedM,M,M
135AlbatrossesBotswanaSoldM,M,M
136AlcidsBotswanaSoldN
TARGET


00 DUMMY ZERO - II.xlsx
ABC
1SPECIECOUNTRYSTATUS
2American flamingoAfghanistanHatched
3AlcidsAfghanistanHatched
4Amazon kingfisherAfghanistanHatched
5AlbatrossesAfghanistanSold
6AlbatrossesAfghanistanSold
7Accipiter hawksAfghanistanSold
8Accipiter hawksAfghanistanSold
9American dipperAlbaniaHatched
10Accipiter hawksAlbaniaHatched
11AlbatrossesAlbaniaSold
12American flamingoAlgeriaHatched
13AlbatrossesAlgeriaSold
14AlbatrossesAlgeriaSold
15Accipiter hawksAlgeriaSold
16American dipperAndorraHatched
17AlcidsAndorraHatched
18AlbatrossesAndorraSold
19AlbatrossesAndorraHatched
20Accipiter hawksAndorraSold
SOURCE
 
Upvote 0
What do you want to copy from where to where ?
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top