vba code to copy/paste values from sheet to sheet if column headings NOT match(but using Mapping of the headers in separate sheet)

SHARATH2394

New Member
Joined
Jun 27, 2019
Messages
2
This is my first post..
I'm attempting to create a macro to do the following:
1.Input contains Mapping Sheet to Match different Headers Ex:
<code>Mapping Sheet
+------+------------+------+
|header 1 | header 2 |
+------+------------+------+
|sam_name | sam.value |
|John_name | John.value |
|Car_name | Car.value |
+------+------------+------+</code>
  1. I have another two sheets say Source and Target sheet Source sheet has header2 values as Headers in Column2(ex:sam.value, John.value, etc.,) and Target sheet headers has header1 values as headers in Column1 (ex: sam_name, John_name etc)
  2. I need to copy paste the values from Source sheet headers to Target sheet sheet under Column2 by mapping the correct respective headers from mapping sheet.

Please do help me with this Thank you in advance
 
Last edited by a moderator:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This is my first post..
I'm attempting to create a macro to do the following:
1.Input contains Mapping Sheet to Match different Headers Ex:
<code>Mapping Sheet
+------+------------+------+
|header 1 | header 2 |
+------+------------+------+
|sam_name | sam.value |
|John_name | John.value |
|Car_name | Car.value |
+------+------------+------+</code>
  1. I have another two sheets say Source and Target sheet Source sheet has header2 values as Headers in Column2(ex:sam.value, John.value, etc.,) and Target sheet headers has header1 values as headers in Column1 (ex: sam_name, John_name etc)
  2. I need to copy paste the values from Source sheet headers to Target sheet sheet under Column2 by mapping the correct respective headers from mapping sheet.
  3. I need to copy paste the values from Source sheet headers to Target sheet sheet under Column2 by mapping the correct respective headers from mapping sheet.

Please do help me with this Thank you in advance

Please find below the codes i have worked on

Set sc = ThisWorkbook.Sheets("conf_sheet") 'Contains Mapping of headers of source and Target sheet
Set ws1 = ThisWorkbook.Sheets("Source_sheet")
Set scrsh = ThisWorkbook.Worksheets("Target_sheet")

wrow = ws1.UsedRange.Rows.Count
wcol = ws1.UsedRange.Columns.Count
srow = sc.UsedRange.Rows.Count
scol = sc.UsedRange.Columns.Count

counter = 0
cnt = 0

For i = 2 To srow
For j = 1 To wcol
If InStr(1, UCase(ws1.Cells(sc.Cells(i, 4).Value, j).Value), UCase(sc.Cells(i, 1).Value), vbTextCompare) > 0 Then
Range(scrsh.Cells(2, counter + 1), scrsh.Cells(wrow, counter + 1)).Value = Range(ws1.Cells(3, j), ws1.Cells(wrow, j)).Value
counter = counter + 1

End If
End If
cnt = cnt + 1
Next j
Next i


I have messed up the above codes please help me with this
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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