Results 1 to 4 of 4

Match column between two sheets and copy row format once column number matches

Threaded View

  1. #1
    Registered User
    Join Date
    07-09-2010
    Location
    Delhi NCR, India
    MS-Off Ver
    Excel 2003
    Posts
    46

    Match column between two sheets and copy row format once column number matches

    Hello,

    Can someone look at the below code and tell me where I am making mistake. I have written this code to match a column between two tabs "Main" and "Backup". If the column number matches, the code should copy the row formatting of that column number from "Backup" sheet to "Main" sheet.

    Currently, it is copying the formatting from "Main" sheet to "Main" sheet itself. Dont know where I am making mistake. Thanks.

    Sub Rowformat()
    
    Dim Sht1Rng As Range
    Dim Sht2Rng As Range
    Dim D As Range
    
    'Compares the ID cell in both worksheets to each other
    
    Set Sht1Rng = Worksheets("Main").Range("B6", Worksheets("Main").Range("B65536").End(xlUp))
    
    Set Sht2Rng = Worksheets("Backup").Range("B6", Worksheets("Backup").Range("B65536").End(xlUp))
    
    For Each B In Sht1Rng
    Set D = Sht2Rng.Find(B.Value, LookIn:=xlValues)
    
    'If same value found in col B of "Backup" sheet then copy
    If Not D Is Nothing Then
                
                Sheets("Backup").Select
                Range(Cells(D.Row, 1), Cells(D.Row, 58)).Copy
                
                Sheets("Main").Select
                Range(Cells(D.Row, 1), Cells(D.Row, 58)).PasteSpecial xlPasteFormats
                            
                
    End If
    Set D = Nothing
    
    Next B
    
    End Sub
    Last edited by kapil; 07-30-2010 at 07:54 AM. Reason: made a small change in code

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