+ Reply to Thread
Results 1 to 3 of 3

Object Variable or With Block Variable Not Set

  1. #1
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Object Variable or With Block Variable Not Set

    Hello excelforum community!
    So,
    I'm getting this error (the title) - "Object Variable or With Block Variable Not Set." I did some googling before posting here and it seems that this basically means I'm using an invalid variable (or the variable doesn't have a value). I declared all my variables right at the start and immediately set them equal to something.

    I suspect the error is either with what I set my variables to, the operations I did with the variables later (such as: first = first.offset(4,0) ) or maybe something with a way I'm supposed to handle variables when their in nested Ifs or in nested Loops?(because I have both).
    I'd really appreciate any insight anyone has into this.

    If you have any questions just let me know! I can be as accommodating as you need.


    Sub listHoldings()
    Dim first As Range
    Dim second As Range
    Dim start As Range

    first = Range("BL13")
    second = Range("BM13")
    start = Range("BR13")
    start.Select
    Do
    Do
    If ActiveCell.Value = "1" Then
    first.Value = ActiveCell.Offset(-1, 0).Value
    ActiveCell.Offset(0, 1).Select
    Else
    If ActiveCell.Value = "2" Then
    second.Value = ActiveCell.Offset(-1, 0).Value
    Else
    ActiveCell.Offset(0, 1).Select
    End If
    End If

    Loop Until IsEmpty(first) = False And IsEmpty(second) = False

    first = first.Offset(4, 0)
    second = second.Offset(4, 0)
    start = start.Offset(4, 0)

    Loop Until IsEmpty(first.Offset(0, -3))

    End Sub

  2. #2
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Object Variable or With Block Variable Not Set

    Please Login or Register  to view this content.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Object Variable or With Block Variable Not Set

    Hi Nicholas,

    In VBA Object VAriables must be Set i.e.

    Please Login or Register  to view this content.
    That should get you started
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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