Copying data from one sheet to next sheet

krishna334

Active Member
Joined
May 22, 2009
Messages
391
Hi All,

I have 2 sheets in my workbook - A and B
In the first row of each sheet i have headers.
But only sheet A has data under each header.
What i need is :

Headers in sheet B's first row has to be searched in sheet A and if the same header exist in sheet A, copy all data under the header in sheet A and paste it under corresponding header in sheet B.

I used the below code but doesn't work if a header in B does not match with any of the headers in A. I want the code to be modified as if B header does not match skip it and continue with the next header in B.

Sub arrange()

Dim i, j As Integer, k As Long, x As String

k = Sheets("A").Range("A65536").End(xlUp).Row

i = 1

For i = 1 To 3


Sheets("A").Select
Cells.Find(What:=Sheets("B").Cells(1, i).Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(k - 1, 0)).Copy Destination:=Sheets("B").Cells(1, i).Offset(1, 0)




Next i

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi,

U just use this below action ...and check

open the sheet 1 (which is having header & footer) go to file^pagesetup^Header footer and Click OK

select the anotther Sheets and press F4....


$ Nilesh $
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,270
Members
452,902
Latest member
Knuddeluff

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