'Merging' with condidtions

gjgj

New Member
Joined
Jan 10, 2011
Messages
15
Hi all,
sorry if this was covered already but I couldn't find a thread that matches my problem.

Basically I have two documents, they are both the same file basically, but one is an update on the other.
The info inside is a list of values (usually text but sometimes is numbers - a string table for a piece of software using text if you're interested).
Each cell with a piece of valuable data is catalogued with a reference name or number (an ID).
The layout is very simple:
The ID is in Col A, and the data is in B. So it might look like:
ID | Data
1a | John
2b | Clare
3c | Stephen

What I do is update the data in Col.B for any errors, then highlight the cell in a colour. Problem is that midway through this job I get an updated file with new lines and I have to merge the data to the correct place in the new file.
So for eg. , lets say I edited line 2b in file 1 from the above to:
ID | Data
1a | John
2b | Clairé
3c | Stephen

Then I get a new file and the latest version looks like:
ID | Data
1a | John
2bx | Sam
2b | Clare
3c | Stephen

So I can't just copy paste the whole column, as the lines have moved essentially. Is there a way of getting Excel to check each cell, see if I have highlighted it green then copy paste it to the row with the right ID?

Thanks in advance! PS I've used Excel a fair amount, but never anything very complicated formula wise (never created a Maco for eg.)
:)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi gjgj,

Welcome to the Forums.

I have made a couple of assumptions for this code but we can change it if you need to.

1st - The workbook that you have been working on (the one with the updates) has been copied to a sheet in the New Workbook and Called Old Sheet

2nd - The sheet in the new workbook has been called New Sheet.

3rd - rather than searching by Cell colour I have simply just searched by ID, this will only work if you IDs are unique, if not will try and change to index color as your asked :)

Code:
Sub Sheet_Update()

    Dim IDstring As String
    Dim LastRow As Integer
    Dim IDint As Integer
    Dim i As Integer

    LastRow = Sheets("New Sheet").Columns(1).Find("*", SearchDirection:=xlPrevious).Row
    
            For i = 2 To LastRow
            On Error GoTo Here
            IDstring = Cells(i, 1).Value
            IDint = Sheets("Old Sheet").Columns(1).Find(IDstring, SearchDirection:=xlPrevious).Row

                If Sheets("New Sheet").Cells(i, 2).Value = Sheets("Old Sheet").Cells(IDint, 2).Value Then
                'Do Nothing As Both Values are the Same
                Else
                Sheets("New Sheet").Cells(i, 2).Value = Sheets("Old Sheet").Cells(IDint, 2).Value
                End If
Here:
            Next i

End Sub

Try this and see how it goes.

/Comf
 
Upvote 0
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-GB</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;} </style> <![endif]--> Wow that's excellent, many thanks!!!!

...but (give an inch take a mile eh?) if it's not a huge problem could I ask for some alterations?

1) Is it possible to do this between files? I ask as a lot of the time the files can be very large and have many sheets/tabs. Coping from the new file to the old whole tabs would be a large job by itself. Ideally this would be great if it could be done on a tab by tab basis between 2 separate files.

2) Does this work across other Columns? Sometimes it is not just names in ColB for instance, it can be further pieces of info in Col C / D / E etc etc

3) If possible can this work by cell colour highlighting or font colour or something? Mainly because if I receive a file with updates in it and new row has been inserted with errors introduced by someone else then I'll take responsibility if the correction is not highlighted if you know what I mean (which is why my changes must be distinguished in some way).

I know I'm asking a lot but I'll promote this site loads and click on the right a ds :p !!

Thanks again
 
Upvote 0
Hi gjgj,

Try the following

Code:
Sub Sheet_Update()
    
    Dim WBold As Workbook
    Dim WSold As Worksheet
    
    Dim WBnew As Workbook
    Dim WSnew As Worksheet
    
    Dim strPath As String
    Dim IDstring As String
    Dim LastRow As Integer
    Dim LastCol As Integer
    Dim IDint As Integer
    Dim i As Integer
    Dim j As Integer

    strPath = Application.GetOpenFilename(, , "Select your original File")
    Set WBold = Application.Workbooks(GetFilenameFromPath(strPath))
    Set WSold = WBold.Worksheets("old")
    
    strPath = Application.GetOpenFilename(, , "Select your new File")
    Set WBnew = Application.Workbooks(GetFilenameFromPath(strPath))
    Set WSnew = WBnew.Worksheets("new")
    
    LastRow = WSold.Columns(1).Find("*", SearchDirection:=xlPrevious).Row
    LastCol = WSold.Rows(1).Find("*", SearchDirection:=xlPrevious).Column
    
            For i = 2 To LastRow
                For j = 2 To LastCol
            On Error GoTo Here
            IDstring = WSold.Cells(i, 1).Value
                If WSold.Cells(i, j).Interior.ColorIndex = 4 Then
                    IDint = WSnew.Columns(1).Find(IDstring, SearchDirection:=xlPrevious).Row
                    WSnew.Cells(IDint, j).Value = WSold.Cells(i, j).Value
                    WSnew.Cells(IDint, j).Interior.ColorIndex = WSold.Cells(i, j).Interior.ColorIndex
                Else
                End If
Here:
                Next j
            Next i

End Sub
 Function GetFilenameFromPath(ByVal strPath As String) As String
    
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
        GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If
End Function

This will open two file browser windows for you to chose the files. They must be open prior to starting the Macro. I haven't included a "Check File is Open" if statement.

For now the sheets must be called "New" and "Old" you can obviously change this or there maybe another way to dynamically set these.

This will update the New Wrkbk sheet with the Old updated value and also make the Cell Green (Color Index 4).

At the moment Each Worksheet must have the same column layout. But it wouldn't be too difficult to change this if they are not.

I think that was everything.

/Comf
 
Upvote 0
Thank you very much again for your response! One problem though -- I can't get it to work:p

I paste and play, choose the Marco name (Sheet_Update) and choose the files. No warning or errors appear. I go back to the files and they are as they were with no texts updated. I tried naming the tabs old - new / Old - New but it doesn't make a difference. I tried creating two new files from scratch but again no result.

Also, if I could be ultra cheeky, there was one thing that you mentioned you updated: the cells that are exported from the old sheet will then be highlighted green in the new sheet. If at all possible, can the script look for cells in the old sheet/file that are highlighted and only export these to the new sheet/file (and also highlight in the new file)?
What can happen sometimes is that a new file recieved would contain changes to cells that I didn't touch. If the script exports all differences (non-highlighted cells included) then these would be overwritten. I can always identify my changes with font colour or something else if cell fill can't be used...

I know I'm asking for quite a bit at this stage, so if it's not possible then no worries :)

Thanks again!!!!!!
 
Upvote 0
A Reason that it may not be working is due to the cell colour you are using, macro is using. The colour index has been set to 4.


Also, if I could be ultra cheeky, there was one thing that you mentioned you updated: the cells that are exported from the old sheet will then be highlighted green in the new sheet. If at all possible, can the script look for cells in the old sheet/file that are highlighted and only export these to the new sheet/file (and also highlight in the new file)?

This is what the Macro currently does.

It will search your old sheet for cells that are filled with Light Green, index 4, take the value of this Cell and Paste it into the New sheet based on the ID Value in Column A and the Column Number of the Cell. It will then change this Cell to Light Green Also.

there are some Custom Functions Here that will help you to find what the index number is of the colour you are using.

Once you find out the Index Number Change it Here:

Code:
If WSold.Cells(i, j).Interior.ColorIndex = 4 Then 'Change This ColorIndex Number
                    IDint = WSnew.Columns(1).Find(IDstring, SearchDirection:=xlPrevious).Row
                    WSnew.Cells(IDint, j).Value = WSold.Cells(i, j).Value
                    WSnew.Cells(IDint, j).Interior.ColorIndex = WSold.Cells(i, j).Interior.ColorIndex
                Else
                End If
 
Upvote 0
Hello again, I'm back with a small request for an amendment:

is it possible to have this function work without specifying tab names? I have come accross files with a huge amount of tabs and it's almost not worth using the Marco with it! The tab names are always the same between the two files.

Thanks again! :)
 
Upvote 0
Emailed to you but posted here for anyone else's perusal.

Code:
Sub Sheet_Update()
    
    Dim WBold As Workbook
    Dim WSold As Worksheet
    
    Dim WBnew As Workbook
    Dim WSnew As Worksheet
    
    Dim ws As Worksheet
    
    Dim strPath As String
    Dim IDstring As String
    Dim LastRow As Integer
    Dim LastCol As Integer
    Dim IDint As Integer
    Dim i As Integer
    Dim j As Integer

    strPath = Application.GetOpenFilename(, , "Select your original File")
    If strPath = "" Then Exit Sub
    Set WBold = Application.Workbooks(GetFilenameFromPath(strPath))
    
    strPath = Application.GetOpenFilename(, , "Select your new File")
    If strPath = "" Then Exit Sub
    Set WBnew = Application.Workbooks(GetFilenameFromPath(strPath))
    
    For Each ws In WBold.Worksheets
    
    Set WSold = ws
    Set WSnew = WBnew.Worksheets(ws.Name)
    
    LastRow = WSold.Columns(1).Find("*", SearchDirection:=xlPrevious).Row
    LastCol = WSold.Rows(1).Find("*", SearchDirection:=xlPrevious).Column
            For i = 2 To LastRow
                For j = 2 To LastCol
                    On Error GoTo Here
                    IDstring = WSold.Cells(i, 1).Value
                    If WSold.Cells(i, j).Interior.ColorIndex = 43 Then
                        IDint = WSnew.Columns(1).Find(IDstring, After:=WSnew.Cells(1, 1), LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
                        WSnew.Cells(IDint, j).Value = WSold.Cells(i, j).Value
                        WSnew.Cells(IDint, j).Interior.ColorIndex = WSold.Cells(i, j).Interior.ColorIndex
                    Else
                    End If
Here:
                Next j
            Next i
    Next

End Sub
 Function GetFilenameFromPath(ByVal strPath As String) As String
    
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
        GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If
End Function
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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