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

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

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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:
    Mapping Sheet
    +------+------------+------+
    |header 1 | header 2 |
    +------+------------+------+
    |sam_name | sam.value |
    |John_name | John.value |
    |Car_name | Car.value |
    +------+------------+------+

    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 Joe4; Jun 27th, 2019 at 03:53 PM.

  2. #2
    New Member
    Join Date
    Jun 2019
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    Quote Originally Posted by SHARATH2394 View Post
    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:
    Mapping Sheet
    +------+------------+------+
    |header 1 | header 2 |
    +------+------------+------+
    |sam_name | sam.value |
    |John_name | John.value |
    |Car_name | Car.value |
    +------+------------+------+

    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •