title: import data from external workbook that has matching row and column id
body: <p>This is my first time posting here</p>
  
  <p>I have an <strong>error</strong>: </p>
  
  <p><code>error 91 Object variable or With block variable not set</code></p>
  
  <p>on the line <code>r2Val = activSheet.Columns(1).Find</code>...</p>
  
  <p>I have been doing this for a month now and got stuck to the import part</p>
  
  <p>This is the sheet update list
  <a href="http://www.mediafire.com/view/?av8skl7e3ry93p3" rel="nofollow">www.mediafire.com/view/?av8skl7e3ry93p3</a> 
  The above opens a file browser to pick a workbook with the sheet to import</p>
  
  <p>This is the sheet that I want filled
  <a href="http://www.mediafire.com/view/?r7y2xfa2s7kc9wx" rel="nofollow">http://www.mediafire.com/view/?r7y2xfa2s7kc9wx</a></p>
  
  <p>This is where it will get the data from
  <a href="http://www.mediafire.com/view/?6wp8ywme1kgehqn" rel="nofollow">http://www.mediafire.com/view/?6wp8ywme1kgehqn</a></p>
  
  <p>My current code for this to work:</p>
  
  <pre><code>' updates data based on excel or csv file uploaded
  ' This version uses "find" to find similar meterID and billing period between 2 worksheets
  Sub Push2Sheets(filePath As String, shtName As String)
      On Error GoTo ErrorHandler
      If filePath = "False" Then Exit Sub
  
      Dim targetWorkbook As Workbook 'workbook to get data from
      Dim MyWorkbook As Workbook 'this workbook to merge
  
      Set MyWorkbook = Application.ActiveWorkbook 'sets this workbook for merging
      Set targetWorkbook = Application.Workbooks.Open(filePath) 'copies source workbook to memory
  
      Dim activSheet As Worksheet
      Set activSheet = MyWorkbook.Worksheets(shtName) 'selects the worksheet to merge with source sheet
      Dim sourceSheet As Worksheet
      If targetWorkbook.Sheets.Count &gt; 1 Then 'checks first if the target workbook has one or many sheets to draw data
          Set sourceSheet = targetWorkbook.Worksheets(1)
          Else
          Set sourceSheet = targetWorkbook.Worksheets(shtName)
      End If
  
      Dim rw As Long 'used as a counter for reading the first column of the source sheet
      Dim Col As Long 'used as a counter for reading the first row of the source sheet
      Dim rVal As String, r2Val As Range 'row value
      Dim cVal As String, c2Val As Range 'cell value
  
      For rw = 2 To sourceSheet.Rows.Count
      rVal = sourceSheet.Cells(rw, 1).Value
      Debug.Print rVal
          'this finds if there is a similar meterID in the target sheet (This Workbook)
          r2Val = activSheet.Columns(1).Find(What:=rVal, LookIn:=xlValues, _
                  LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                  MatchCase:=False, SearchFormat:=False)
          If Not r2Val Is Nothing Then
              For Col = 2 To sourceSheet.Columns.Count
              cVal = sourceSheet.Cells(1, Col).Value
              Debug.Print cVal
                  'uses the table headers to find a match and copies the content of source to target sheet if found
                  c2Val = activSheet.Rows(1).Find(What:=cVal, LookIn:=xlValues, _
                          LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
                          MatchCase:=False, SearchFormat:=False)
                  If Not c2Val Is Nothing Then
                  sourceSheet.Cells(rw, Col).Copy Destination:=activSheet.Cells(r2Val.Row, c2Val.Column)
                  End If
              Next
          Else
              Call UniAutoFiller 'adds a new row at the end of the table if there is a new MeterID
              [addrow].Offset(-1, 0).Value = rVal
          End If
      Next
  
      targetWorkbook.Close SaveChanges:=False
      Exit Sub
  
  ErrorHandler:
      If Not err.Number = 0 Then Call LogInformation(ThisWorkbook.Name &amp; " has error " &amp; err.Number &amp; " " &amp; err.Description &amp; " on " &amp; Format(Now, "yyyy-mm-dd hh:mm"))
      MsgBox "Something went wrong :?" &amp; vbNewLine &amp; vbNewLine &amp; "Make sure the worksheet name you" &amp; _
       vbNewLine &amp; "are importing match the internal sheet name"
  End Sub
  </code></pre>
  
  <p>I'm still a novice when it comes to excel vba</p>
  
  <p>What I want it to do is to:</p>
  
  <ol>
  <li>open the external workbook, with the full accomplished worksheet</li>
  <li>find a match on the meterID with the meterID of the internal sheet,</li>
  <li>if found find a match on the billing period (date) on the column, if</li>
  <li>found copy the data where the meterID and billing period got a match</li>
  <li>repeat 1-4 until it reaches the end of the table</li>
  </ol>
  
  <p>if you want to see the source
  get it here: <a href="http://www.mediafire.com/?9z924s7wtrb5md3" rel="nofollow">www.mediafire.com/?9z924s7wtrb5md3</a></p>
  
  <p>this is the sheet I'm trying to import: <a href="http://www.mediafire.com/view/?i7td9gm336wg6cg" rel="nofollow">www.mediafire.com/view/?i7td9gm336wg6cg</a></p>
  
  <p>I cant post images and links yet so if mods or mod class user can clean this up then Im grateful</p>
  
  <p>Any advice, corrections, tips will really help</p>