Need Help Please

reel03

New Member
Joined
Apr 25, 2017
Messages
6
Hi guys,
i need help.
i want to do copy-paste diffirent worksheet but with for next loop
for example:
Worksheets("Sheet1").Range("a1").copy = Worksheets("Sheet2").Range("a1").copy
Worksheets("Sheet1").Range("a2").copy = Worksheets("Sheet2").Range("a2").copy
etc...

Sheet1:


Sheet2




i have code but not working...
Sub for_loop()
Set wks = Worksheets("Sheet1")
On Error Resume Next

For i = 2 To wks.Range("A1" & Rows.Count).End(xlUp).Row
Worksheets("Sheet1").Range("A2").Value = Worksheets("Sheet2").Range("A2").Value
Next i


End Sub
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,012
Office Version
2016
Platform
Windows
You don't need a loop :

Code:
With Worksheets("Sheet1")
    .Range(.[A1], .Cells(Rows.Count, "A").End(xlUp)).Copy Sheets("Sheet2").[A1]
End With
 

reel03

New Member
Joined
Apr 25, 2017
Messages
6
thanks for answer. But i want to do single copy later copied value export pdf file.
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,012
Office Version
2016
Platform
Windows
Code:
Sub for_loop()
Dim wks As Worksheet, n&
Set wks = Worksheets("Sheet1")
n = wks.Range("A1" & Rows.Count).End(xlUp).Row
For i = 1 To n
    Worksheets("Sheet2").Range("A" & i) = wks.Range("A" & i).Value
Next i
End Sub
 

reel03

New Member
Joined
Apr 25, 2017
Messages
6
error code n& ?
Can u help me again


Code:
Sub for_loop()
Dim wks As Worksheet, n&
Set wks = Worksheets("Sheet1")
n = wks.Range("A1" & Rows.Count).End(xlUp).Row
For i = 1 To n
    Worksheets("Sheet2").Range("A" & i) = wks.Range("A" & i).Value
Next i
End Sub
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,012
Office Version
2016
Platform
Windows
Code:
Sub for_loop()
Dim wks As Worksheet, n&
Set wks = Worksheets("Sheet1")
n = wks.Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To n
    Worksheets("Sheet2").Range("A" & i) = wks.Range("A" & i).Value
Next i
End Sub
 

reel03

New Member
Joined
Apr 25, 2017
Messages
6
thank you so much.
Well, how do just sheets2 A1 COPY, but with for next loop

for example .
Sheet1.a1.copy = Sheet2.a1.value
Sheet1.a2.copy = Sheet2.a1.value
Sheet1.a3.copy = Sheet2.a1.value



Code:
Sub for_loop()
Dim wks As Worksheet, n&
Set wks = Worksheets("Sheet1")
n = wks.Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To n
    Worksheets("Sheet2").Range("A" & i) = wks.Range("A" & i).Value
Next i
End Sub
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,012
Office Version
2016
Platform
Windows
thank you so much.
Well, how do just sheets2 A1 COPY, but with for next loop

for example .
Sheet1.a1.copy = Sheet2.a1.value
Sheet1.a2.copy = Sheet2.a1.value
Sheet1.a3.copy = Sheet2.a1.value
The code I posted copies from Sheet1 and pastes to Sheet2.
If you want to do the other way around, just switch the sheet refs in the code.
( wks.Range("A" & i) = Worksheets("Sheet2").Range("A" & i).Value )
If you want something different, post again since I don't understand.
 
Last edited:

reel03

New Member
Joined
Apr 25, 2017
Messages
6
thank you answer. i fixed problem.
Best regards.


The code I posted copies from Sheet1 and pastes to Sheet2.
If you want to do the other way around, just switch the sheet refs in the code.
( wks.Range("A" & i) = Worksheets("Sheet2").Range("A" & i).Value )
If you want something different, post again since I don't understand.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,029
Messages
5,466,117
Members
406,468
Latest member
Toto Li

This Week's Hot Topics

Top