Consulting

Results 1 to 5 of 5

Thread: Macro that copies data and format Worksheet to worksheet

  1. #1
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location

    Macro that copies data and format Worksheet to worksheet

    Hello,

    I am looking to create a macro that will use 2 worksheets in the same macro book. I want the data and format from one sheet to be copied to the other sheet if the values match in column A.
    ****************************
    I do not want colums I,J,K,L,O, or P to be copied
    ****************************
    For example.

    in Worksheet 1 I have data in A4:P50 (some cells are highlighted)
    in Worksheet 2 i have data in A4:P90

    If A7 from worksheet 1 and A12 from worksheet 2 match, I want to copy A7:H7 and M7:N7 (format and all) to A9:H9 and M9:N9.

    This should happen for all matching values in the A column from worksheet 1 to worksheet 2.
    If the cells don't match the value should stay the same.

    P.S. there will be more than 50 rows of data, so i need it to do this until the last row of data.
    Last edited by Zlerp; 09-15-2014 at 02:32 PM.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by Zlerp View Post
    If A7 from worksheet 1 and A12 from worksheet 2 match, I want to copy A7:H7 and M7:N7 (format and all) to A9:H9 and M9:N9.
    Could you explain the logic of the red row numbers?

  3. #3
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location

    Macro that copies data and format Worksheet to worksheet

    Quote Originally Posted by p45cal View Post
    Could you explain the logic of the red row numbers?
    Worksheet 1 has data in A4:P50
    Worksheet 2 ihashave data in A4:P90 (some cells are highlighted)
    Example-Help - Copy.xls
    If A9 from worksheet 1 and A7 from worksheet 2 match, I want to copy A7:H7 and M7:N7 (format and all) from worksheet 2 to A9:H9 and M9:N9 on worksheet 1.
    This should happen for all matching values in the A column on worksheet 1 and worksheet 2.
    If the cells don't match the value should stay the same.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Sub blah()
    Dim xx As Range
    With Sheets("Worksheet2")
    For Each cll In .Range(.Cells(4, 1), .Cells(3, 1).End(xlDown)).Cells
      Set xx = Sheets("Worksheet1").Columns(1).Find(what:=cll.Value, LookAt:=xlWhole, LookIn:=xlFormulas, searchformat:=False)
      If Not xx Is Nothing Then
        cll.Resize(, 8).Copy xx
        cll.Offset(, 12).Resize(, 2).Copy xx.Offset(, 12)
      End If
    Next cll
    End With
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location
    Quote Originally Posted by p45cal View Post
    try:
    Sub blah()
    Dim xx As Range
    With Sheets("Worksheet2")
    For Each cll In .Range(.Cells(4, 1), .Cells(3, 1).End(xlDown)).Cells
      Set xx = Sheets("Worksheet1").Columns(1).Find(what:=cll.Value, LookAt:=xlWhole, LookIn:=xlFormulas, searchformat:=False)
      If Not xx Is Nothing Then
        cll.Resize(, 8).Copy xx
        cll.Offset(, 12).Resize(, 2).Copy xx.Offset(, 12)
      End If
    Next cll
    End With
    End Sub
    Seems to work Perfect!!! thanks for the help!

Posting Permissions

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