copy multiple cells t

jolyji

New Member
Joined
May 27, 2020
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
  2. MacOS
I am trying to copy data from source WS to destination WS. I would like to know if I can use a loop to achieve the below result to avoid writing a long number of lines as shown below; Can someone help me to achieve this.

Sub Submit()

Dim sh As Worksheet

Dim sh1 As Worksheet

Dim iRow As Long

Set sh = ThisWorkbook.Sheets("Data_Input")

Set sh1 = ThisWorkbook.Sheets("Data_Source")

iRow = [Counta(Data_input!A:A)] + 1

sh.Range("A" & Last_Row + 1).Value = "=IF(B" & Last_Row + 1 & "="""","""",ROW()-1)"

With sh

.Cells(iRow, 2) = sh1.Range("C5").Value
.Cells(iRow, 3) = sh1.Range("C6").Value
.Cells(iRow, 4) = sh1.Range("C7").Value
.Cells(iRow, 5) = sh1.Range("C8").Value
.Cells(iRow, 6) = sh1.Range("C9").Value
.Cells(iRow, 7) = sh1.Range("C10").Value
.Cells(iRow, 8) = sh1.Range("d11").Value
.Cells(iRow, 9) = sh1.Range("G12").Value
.Cells(iRow, 10) = sh1.Range("G13").Value
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I got an idea to achieve the same result with the below code and it worked. Thanks

The below code will reduce the number of lines from 10 to 5.

c=4
for i = 2 to 11
c = c+1
Cells(iRow, i) = sh1.Range("C" & c).Value
Next i
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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