Loop through Columns and copy data based on conditions

newtoexcelvba

New Member
Joined
Jun 26, 2011
Messages
2
Hi All,

I am new to this post, i would like your help on a personal project i am working on.

I have a worksheet (SHEET1) with two columns of data

ColumnA ColumnB
Plant Number XABJ020
Warehouse T50
HoursRun 400
Plant Number P5767
Warehouse L0U
Hours Run 500

i have sheet2 where in i have created heads for each category from columnA of sheet1 as below,

PlantNumber Warehouse HoursRun





can someone help me to write a code to loop through each cells of column A and B in sheet1 and arrange data from columnB to sheet2 as below ?


PlantNumber Warehouse HoursRun
XABJ020 T50 400
P5767 L0U 500

Thanks and Regards
newtoexcelvba
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try

Code:
Sub Xpose()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR - 2 Step 3
        Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Application.Transpose(.Range("B" & i).Resize(3))
    Next i
End With
End Sub
 
Upvote 0
Hi Vog,

thanks for the quick response, i have tried the code you suggested, the problem is it copies all the data into sheet2, without allocating it into three columns, right now its appearing as below:

PlantNumber Warehouse
hours

instead of

PlantNumber Warehouse Hours


thanks
 
Upvote 0
Before

Excel Workbook
AB
1PlantNumberXABJ020
2WarehouseT50
3HoursRun0400
4PlantNumberP5767
5WarehouseL0U
6Hours0500
Sheet1




Code:
Sub Xpose()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR - 2 Step 3
        Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Application.Transpose(.Range("B" & i).Resize(3))
    Next i
End With
End Sub

After

Excel Workbook
ABC
1PlantNumberWarehouseHoursRun
2XABJ020T50400
3P5767L0U500
Sheet2
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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