Transfer Data from Sheet1 to Sheet2

How to transfer data from Sheet1 to Sheet2 using a looping process without the offset function. Today we learn again how to use a ‘do while’ loop and about variables.

Watch the training video and then study the VBA code step by step:

Watch this video on YouTube.

Here’s the complete VBA code to transfer data from one worksheet to another:

Sub transferData()
Application.ScreenUpdating = False
Dim sh1 As Worksheet, sh2 As Worksheet
Dim ItemName As String
Dim price As Long, qty As Long
Set sh1 = Sheets(“Sheet1”)
Set sh2 = Sheets(“Sheet2”)
Range(“A1”).Value = “Item”
Range(“B1”).Value = “Unit Price”
Range(“c1”).Value = “Quantity”
Dim r1 As Long, r2 As Long
r1 = 1
r2 = 2
Do While Cells(r1, 1) <> “”
ItemName = Cells(r1, 2).Value
r1 = r1 + 1
price = Cells(r1, 2).Value
r1 = r1 + 1
qty = Cells(r1, 2)
r1 = r1 + 1
Cells(r2, 1).Value = ItemName
Cells(r2, 2).Value = price
Cells(r2, 3).Value = qty
r2 = r2 + 1


Application.ScreenUpdating = True
End Sub
Further Reading: