Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:29:44+00:00 2026-06-18T01:29:44+00:00

This is my first time posting here I have an error : error 91

  • 0

This is my first time posting here

I have an error:

error 91 Object variable or With block variable not set

on the line r2Val = activSheet.Columns(1).Find…

I have been doing this for a month now and got stuck to the import part

This is the sheet update list
http://www.mediafire.com/view/?av8skl7e3ry93p3
The above opens a file browser to pick a workbook with the sheet to import

This is the sheet that I want filled
http://www.mediafire.com/view/?r7y2xfa2s7kc9wx

This is where it will get the data from
http://www.mediafire.com/view/?6wp8ywme1kgehqn

My current code for this to work:

' 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 > 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 & " has error " & err.Number & " " & err.Description & " on " & Format(Now, "yyyy-mm-dd hh:mm"))
    MsgBox "Something went wrong :?" & vbNewLine & vbNewLine & "Make sure the worksheet name you" & _
     vbNewLine & "are importing match the internal sheet name"
End Sub

I’m still a novice when it comes to excel vba

What I want it to do is to:

  1. open the external workbook, with the full accomplished worksheet
  2. find a match on the meterID with the meterID of the internal sheet,
  3. if found find a match on the billing period (date) on the column, if
  4. found copy the data where the meterID and billing period got a match
  5. repeat 1-4 until it reaches the end of the table

if you want to see the source
get it here: http://www.mediafire.com/?9z924s7wtrb5md3

this is the sheet I’m trying to import: http://www.mediafire.com/view/?i7td9gm336wg6cg

I cant post images and links yet so if mods or mod class user can clean this up then Im grateful

Any advice, corrections, tips will really help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:29:46+00:00Added an answer on June 18, 2026 at 1:29 am

    At a glance the cause of line 91 error is that you try to set Range using just =, while Set should be used instead, i.e.:

    Set r2Val = activSheet.Columns(1).Find(What:=rVal, LookIn:=xlValues, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
    

    The same is true for c2Val below. Try to correct these first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time posting here, I have a question which I have
this is my first time posting on here and have read alot of helpful
this is my first time posting here, although I have gotten many great tips
So this is my first time posting here but I'm more or less stumped.
First time posting here. I have problem about referencing a typedef struct from separate
This is my first time posting here, so I apologize in advance for the
This is my first time posting here, but I've found a lot of answers
this is my first time on posting so if I have done anything please
This is my first time posting here. I am using GUI in java for
Well this is not the first time im asking these question here but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.