code transfer all of data & coordinate from sh1 to sh2

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,507
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi guys
i have some datas and coordinates in sheet1 and i have macro buttons to transfer to sheet2
here my code doesn't well work transfer some of data but not all i would in every time to fill data in sheet1 transfer to sheet2 every thing data an coordinate like color


Sub transferData()
Dim i As Long
Dim Lastrow As Long
Dim erow As Long
Lastrow = Sheets("sheet1").Range("a" & Rows.Count).End(xlUp).Row
For i = 3 To Lastrow
erow = Sheets("sheet2").Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Row
Range(Cells(i, 1), Cells(i, 6)).Copy Destination:=sheet2.Cells(erow, 1)
Next i
sheet2.Cells(erow, 6) = WorksheetFunction.Sum(Worksheets("sheet2").Range("e3:e35"))
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try:
Code:
Sub transferData()
    Dim i As Long
    Dim Lastrow As Long
    Lastrow = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
    For i = 3 To Lastrow
        Range("A" & i).Resize(, 6).Copy Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Offset(1, 0)
    Next i
    Sheet2.Cells(Sheet2.Rows.Count, "E").End(xlUp).Offset(1, 0) = WorksheetFunction.Sum(Sheets("Sheet2").Range("E2", Sheets("Sheet2").Range("E" & Sheets("Sheet2").Rows.Count).End(xlUp)))
End Sub
 
Upvote 0
Or maybe
Code:
Sub transferData()
   Dim Lastrow As Long
   
   Lastrow = Sheets("sheet1").Range("a" & Rows.Count).End(xlUp).Row
   Sheets("Sheet1").Range("A3:F" & Lastrow).Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
   With Sheets("Sheet2").Range("E" & Rows.Count).End(xlUp).Offset(1)
      .Value = WorksheetFunction.Sum(Range(.Parent.Cells(3, "E"), .Offset(-1)))
   End With
End Sub
 
Upvote 0
thanks fluff it's perfect code but still one problem the row what contains total not show in sheet2
 
Last edited:
Upvote 0
thanks mumps but the code doesn't work it's the same what i have i'm like you actually newer in vba exel but i love this programming language
 
Upvote 0
The total should appear in column E after the last row of data, are you saying that cell is totally empty?
 
Upvote 0
The total should appear in column E after the last row of data, are you saying that cell is totally empty?

yes there is no last row the total is not exist i have 3 row invisible subtotal,shipping and total i no know why
 
Upvote 0
If you have hidden rows below the data the total will be in the first of them
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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