+ Reply to Thread
Results 1 to 5 of 5

Defining Range with Cells property

  1. #1
    Registered User
    Join Date
    10-22-2011
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    11

    Question Defining Range with Cells property

    Hi all,

    I am trying to define a range (in column N) using the Cells property, so I can later use that range to iterate through it looking for empty cells and filling them.
    As the range I want to analyze (in column N) contains empty cells, I use the range in column B to obtain the number of the last row from the table (=last non empty row)
    The number of the last non empty row in column B (rownumber) is used as an argument in the Cells property used to define the range in column N.

    However, the current way the range is defined in my code gives me the following error:

    Run-time error '91':
    Object variable or With block variable not set


    Could you please help me identify what I am doing wrong?

    Many thanks for your help!

    PS: I cannot paste the VBA code here cause the forum does not allow me. Sorry :/
    Attached Files Attached Files
    Last edited by Eldexoly; 12-08-2021 at 09:16 AM. Reason: [SOLVED]

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,411

    Re: Defining Range with Cells property

    Something like

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-22-2011
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Defining Range with Cells property

    Hi TMS,

    Thank you for your answer! I have seen the code you pasted worked well, but I didn't manage to use it as input when defining a range. I have tried in different ways, but I couldn't (see macro Fill_Planned_v03() of the Excel).

    I made it work with this code, but I wanted to learn why I am not being able to define the Range with the Cells property (see macro Fill_Planned_v01() of the Excel).

    Thanks, and kind regards
    Attached Files Attached Files

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Defining Range with Cells property

    You need to use Set with objects, and you need to qualify Cells with the same sheet as the Range property, so:

    Please Login or Register  to view this content.
    or:

    Please Login or Register  to view this content.
    Rory

  5. #5
    Registered User
    Join Date
    10-22-2011
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Defining Range with Cells property

    Hi royra,

    Thank you for the clarification, it works perfectly now!

    I have included the final working code in the attached Excel for other people reference.

    Have a great day!
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Need help defining a dynamic range of cells to merge
    By bwiddoes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2016, 02:29 PM
  2. Problem Defining Toggle Buttion Value Property as a Variable
    By mandora in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2014, 02:12 AM
  3. [SOLVED] problem defining quote sign " in formula property applied to range object
    By mnjofra in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-07-2012, 05:18 PM
  4. Defining a range with variables and Cells function
    By Apel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2009, 10:29 AM
  5. Defining Range using Cells
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-31-2006, 04:24 AM
  6. Defining a Property
    By Cody in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2005, 09:05 PM
  7. Replies: 2
    Last Post: 03-30-2005, 03:06 PM

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