Import from second workbook plus some magic

keiranwyllie

New Member
Joined
May 12, 2017
Messages
47
Good afternoon Guru's

I'm racking my brain with the best way forward on this. I have two spreadsheets (similar examples attached), one holding source data and the second is used for reporting. The source data comes from another source and therefore doesn't contain comments (column G). The report imports the source data (done weekly) and then tracks specific issues with each job by then adding comments.

The source data is updated externally on a weekly basis and therefore will contain new jobs, or will have removed jobs that have been closed during the previous week (I've explained this veru basically in the flow.jpg attached). The report workbook is something I control that, at this point in time, contains a lot more than the example attached. What I want to be able to do is import the newest source data workbook into the report workbook (to the 'Source' tab). I need to then compare the new source data with the data in the 'Job Comments' tab to both remove closed jobs and add new jobs (into the 'Job Comments' tab) while at the same time retaining any comments in column G for jobs that are still open.

All I can think of is opening each workbook in various orders and copying worksheets back and forth multiple times and using filters to delete certain rows that don't match but my head is hurting from even contemplating that. There has to be an easier way...right. Well hopefully. I'd love just a point in any direction that could possible help. TIA

The files are located here https://github.com/keiranwyllie/excel
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Well I continued to work away at this and I've had success for anyone that may wish to do anything similar. The files are still in the same location if you want to take a look. See below for the code I used.
I feel there is a better way to delete the column in the last part of the code because I'd prefer to only copy a range rather than the entire row however this still gives me the outcome I'm after.

Code:
Sub CheckValues()Dim CurrVal As String
Dim currcell As String
Dim ChkVal As Variant
Dim lr As Long
Dim chklr As Long
Dim rngtochk As Range
Dim i As Long
Dim x As Long
Dim fromws As Worksheet
Dim chktows As Worksheet
Dim LastRow As Long
Dim h As Long, j As Long


Worksheets("Job Comments").Activate


Set fromws = Sheets("Job Comments")
lr = fromws.Cells(Rows.Count, "B").End(xlUp).Row




For i = lr To 2 Step -1
    currcell = Cells(i, 2).Value
    For x = 1 To 1
        Select Case x
            Case 1
                Set chktows = Sheets("Source")
                chklr = chktows.Cells(Rows.Count, "B").End(xlUp).Row
                Set rngtochk = chktows.Range("B2:B" & chklr)
        End Select
        If Application.WorksheetFunction.CountIf(rngtochk, currcell) = 0 Then
            fromws.Rows(i).Delete
        End If
    Next
Next


   'Find the last used row in a Column: column A in this example
   With Worksheets("Source")
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   End With


   'MsgBox (LastRow)
   'first row number where you need to paste values in Sheet1'
   With Worksheets("Job Comments")
      j = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
   End With


   For h = 1 To LastRow
       With Worksheets("Source")
           If .Cells(h, 9).Value = "Unique" Then
               .Rows(h).Copy Destination:=Worksheets("Job Comments").Range("A" & j)
               j = j + 1
           End If
       End With
   Next h
   
   Worksheets("Job Comments").Columns(9).ClearContents
   
End Sub

My next attempt will be to grab the new data and add it to an email.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

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