VBA: Change referenced cell for each loop iteration

yits05

New Member
Joined
Jul 17, 2020
Messages
47
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

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,468
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,129,404
Messages
5,636,083
Members
416,897
Latest member
YAFI

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