manjuprasad
New Member
- Joined
- Aug 1, 2022
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I have data in Excel Sheet1, which is as follows:
I have to organize the data where I want to copy all the data rows based on "Column B" into a separate sheet until the last unique value in "Column B", which is shown below: I have around 6000 rows in my data set.
I have developed the following VBA code which copy every 6 rows and paste it in the last empty column in Sheet2. as shown below.
I kindly request if any of you have a solution to organize the data, as shown in image 2 above.
Thanks you in advance.
I have to organize the data where I want to copy all the data rows based on "Column B" into a separate sheet until the last unique value in "Column B", which is shown below: I have around 6000 rows in my data set.
I have developed the following VBA code which copy every 6 rows and paste it in the last empty column in Sheet2. as shown below.
VBA Code:
Sub copyPaste()
Dim x As Long
Dim y As Long
Dim lastRow As Long
Dim sht As Worksheet
Set sht = Worksheets("Sheet1")
y = 6
lastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
'emptyColumn = Sheet2.Cells(2, Columns.Count).End(xlToLeft).Column
For x = 2 To lastRow Step 6
If Worksheets("Sheet2").Cells(2, "A") = "" Then
Worksheets("Sheet1").Range("A" & x & ":D" & y).Copy _
Destination:=Worksheets("Sheet2").Cells(2, "A")
Else
Worksheets("Sheet1").Range("A" & x & ":D" & y).Copy _
Destination:=Worksheets("Sheet2").Cells(2, Columns.Count).End(xlToLeft).Offset(, 1)
End If
y = y + 6
Next
End Sub
I kindly request if any of you have a solution to organize the data, as shown in image 2 above.
Thanks you in advance.