VBA: Change referenced cell for each loop iteration

yits05

Board Regular
Joined
Jul 17, 2020
Messages
52
Office Version
  1. 2016
Platform
  1. Windows
Let me start by saying I am completely new to VBA. I have the following code (dumbed down version of the actual code but captures the essence of my question):

VBA Code:
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To FinalRow
    Sheets("Sheet1").Select
    Range("A2").Select
    Selection.Copy
    Sheets("Sheet1B2").Paste

Next i

It's purpose is to copy cell content from A2 to B2, A3 to B3, and so on for 175 rows. I know I am doing something wrong because there is nothing telling Excel to change the cell reference with each loop. Would appreciate any guidance on how to do this.

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
Hi
VBA Code:
For i = 2 To FinalRow
    Sheets("Sheet1").Select
    Range("A" & i).Select
    Selection.Copy
    Sheets("Sheet1").Range("B" & i).Paste

Next i
 
Solution

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
And try this as well
VBA Code:
For i = 2 To FinalRow
    Sheets("Sheet1").  Range("A" & i).Copy  Sheets("Sheet1").Range("B" & I)

Next i
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,915
Office Version
  1. 365
Platform
  1. Windows
Or without a loop
VBA Code:
   With Sheets("Sheet1")
      .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Copy .Range("B2")
   End With
 

Watch MrExcel Video

Forum statistics

Threads
1,130,220
Messages
5,640,960
Members
417,183
Latest member
CuteLeo

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
Top