+ Reply to Thread
Results 1 to 1 of 1

Code Problem Macro to copy specific cell based on the heading it is next to.

Hybrid View

Mush1138 Code Problem Macro to copy... 12-09-2011, 12:07 PM
  1. #1
    Registered User
    Join Date
    12-09-2011
    Location
    Warrington
    MS-Off Ver
    Excel 2003
    Posts
    1

    Code Problem Macro to copy specific cell based on the heading it is next to.

    Hello All
    I am hoping someone will be able to help, I have searched the internet for similar problems but have come up with nothing.


    I have a form set out in excel and I have started writing a macro adapted from another working macro I found and adapted. I need the macro to find each heading on the form (sheet 2) then copy the data in the cell to the right of those headings. Then paste it into a table on the next sheet (Acquisition) under the appropriate heading without copying over any data that may be already there. The Macro I started below works in part but isn't specific enough, either way I think of changing it, it either copies the whole row or column.

    I have attached the worksheets in question (hopefully)

    Thank you in advance for any help.




    Sub Macromove()
    '
    
    Dim myHeaders, e, x, wsR As Worksheet, wsS As Worksheet
    Dim r As Range, c As Range
    myHeaders = Array(Array("CSID:", "CSID"), Array("O2 CSR:", "O2 CSR"), _
                Array("VF CSR:", "VF CSR"))
    
    Set wsS = Sheets("Sheet2")
    Set wsR = Sheets("Acquisition")
    For Each e In myHeaders
        Set r = wsS.Cells.Find(e(0), , , xlWhole)
        If Not r Is Nothing Then
            Set c = wsR.Cells.Find(e(1), , , xlWhole)
            If Not c Is Nothing Then
                wsS.Range(r.Offset(, 1), wsS.Cells(Rows.Count, r.Column).End(xlUp)).Copy _
                wsR.Cells(Rows.Count, c.Column).End(xlUp)(2)
            Else
                msg = msg & vbLf & e(1) & " " & wsR.Name
            End If
        Else
            msg = msg & vbLf & e(0) & " " & wsS.Name
        End If
    Next
    If Len(msg) Then
        MsgBox "Header not found" & msg
    End If
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1