Simple VBA Code

vijaychennai

Board Regular
Joined
Dec 7, 2009
Messages
239
Hello All,

Good Morning...

Please find the below Excel.


Excel Workbook
ABCDEFGHI
1F2F3F1F5F6F4F7F8F9
2111111111
3111111111
4111111111
5111111111
6111111111
7111111111
8111111111
9111111111
10111111111
11111111111
12111111111
13111111111
14111111111
15111111111
Sheet1


i have excel file in the above format.

I want to data in the below Format.


Excel Workbook
ABC
1F1F2F3
2111
3111
4111
5111
6111
7111
8111
9111
10111
11111
12111
13111
14111
15111
Sheet2


Condition:

in Sheet 1 "F1" Column comes any where. like "F3" Comes 7 column or 8 column or any where. based on heading i want to move f1 , f2 & F3 in sheet2.

Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi. Try this

Code:
Sub CopyData()
Dim i As Long, Found As Range
With Sheets("Sheet1")
    For i = 1 To 3
        Set Found = .Rows(1).Find(what:="F" & i, LookIn:=xlValues, lookat:=xlWhole)
        If Not Found Is Nothing Then Found.EntireColumn.Copy Destination:=Sheets("Sheet2").Cells(1, i)
    Next i
End With
End Sub
 
Upvote 0
Try

Code:
Sub CopyData()
Dim i As Long, Found As Range, X
X = Array("Data", "Student", "Rating")
With Sheets("Sheet1")
    For i = 1 To 3
        Set Found = .Rows(1).Find(what:=X(i - 1), LookIn:=xlValues, lookat:=xlWhole)
        If Not Found Is Nothing Then Found.EntireColumn.Copy Destination:=Sheets("Sheet2").Cells(1, i)
    Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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