+ Reply to Thread
Results 1 to 4 of 4

Object variable or with block variable not set error in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    02-09-2013
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    31

    Object variable or with block variable not set error in VBA

    I have two worksheets, which are Sheet1 and Edit Log. I like to go from Sheet1 to Edit Log and enter some information in the last row in Edit Log. But, I am getting Object variable or with block variable not set runtime error.

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
        ' Other code here to be executed in Sheet1
    
        Dim LastRow As Range
        Sheets("Edit Log").Activate
        Set LastRow = Sheets("Edit Log").Cell(Rows.Count, "A").End(xlUp).Row
        Sheets("Edit Log").Range("A" & LastRow + 1).Value = Format(Now, "dd/mmm/yyyy @ hh:mm:ss AM/PM")
        Sheets("LastSheet").Activate       'Takes me back to Sheet1 after the information is entered in Edit Log.
        
        End If
    End Sub
    Where am I doing wrong?

  2. #2
    Forum Contributor
    Join Date
    01-13-2013
    Location
    Oklahoma
    MS-Off Ver
    Office 2007 / Office 2010
    Posts
    123

    Re: Object variable or with block variable not set error in VBA

    You've got LastRow as a Range but are returning a row number to it which is a Long.

  3. #3
    Registered User
    Join Date
    02-09-2013
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    31

    Re: Object variable or with block variable not set error in VBA

    Thanks for the reply. I was getting Compile error: Object Required when I changed LastRow As Long. But, it worked when I set LastRow as Integer. I don't know why? Any ideas?
    Last edited by Shanthan; 03-20-2013 at 11:45 PM.

  4. #4
    Forum Contributor
    Join Date
    01-13-2013
    Location
    Oklahoma
    MS-Off Ver
    Office 2007 / Office 2010
    Posts
    123

    Re: Object variable or with block variable not set error in VBA

    It's probably the set, it's not needed.

+ Reply to Thread

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