Macro to copy row values based on a identical column headers

Vijaya Pratap

New Member
Joined
Feb 25, 2013
Messages
2
I am pretty new to VBA/Macros. Here is my requirement looking for a solution. I would require a macro, which identifies the row values by Column heading and returns those cell values in another worksheet with the same column headers on the same workbook. These columns are at different ranges on two worksheets and has the cell values starting at different ranges. For example, I have a workbook, with worksheets Summary (Sheet1) and January (Sheet2), I need four columns from Sheet2 (January) starting from Column No. 22 to 25 & rows values in the cells are starting at row 4 and onwards, macro should run to exclude the headers from this sheet and return the values under these columns to Sheet 1(Summary)with the same column headers ranging from column no. 10 to 13 and cell values should begin from row 18 onwards. Hope you have a clear picture of my requirment. Please ask me for any additional questions. Thanks for your help in advance. Please see the attached sample workbook for your reference.
 
Code:
Sub pratap()
Dim sh1 As Worksheet, sh2 As Worksheet, lastr1 As Long, lastr2 As Long

Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
If sh1.Range("J18") = "" Then
lastr1 = 18
Else
lastr1 = sh1.Range("J" & Rows.Count).End(xlUp).Row
End If
lastr2 = sh2.Range("V" & Rows.Count).End(xlUp).Row
sh2.Range(Cells(4, 22), Cells(lastr2, 25)).Copy _
 sh1.Range("J" & lastr1)
End Sub
 
Upvote 0

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