+ Reply to Thread
Results 1 to 9 of 9

Understanding range objects used with .delete/.resize/.offset methods

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Understanding range objects used with .delete/.resize/.offset methods

    I've spent an embarrassing amount of time and frustration simply attempting to delete a cell. Please help me understand the scope of the problem statement in addition to any common techniques for using the subject methods efficiently and concisely.

    A specific problem that highlights my ignorance is described below.

    I will set a range to a cell and attempt to delete it and it consistently deletes the cell just below a given row. I will even go as far as to prove that the cell is set to a given row and column with a MsgBox ("Column: " & rng_todelete.Offset(ColumnOffset:=i).Column & vbCr & "Row: " & rng_todelete.Offset(ColumnOffset:=i).row) line of code just before rng_todelete.Delete and I still delete the cell just below rng_todelete.Delete is located.

    The loop encompassing that Set rng_todelete = rng.Offset(0, i) line is also unnecessary. I can resize that to delete 5 rows with an expression similar to rng.Offset(some arg.).Resize( ColumnSize:= 5).

    Please help me understand .delete/.resize/.offset methods. I'm trying very hard to avoid .selection/.select methods.

    All this code is trying to do is compare 5 consecutive cells of code and delete duplicate sets of 5 identical consecutive cells across a few hundred columns. This should be very simple.
    Please Login or Register  to view this content.
    Thank you
    <---If my answer helped, please click *

  2. #2
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Understanding range objects used with .delete/.resize/.offset methods

    The particular workbook I'm operating on may be found here: http://www.excelforum.com/excel-prog...uplicates.html

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Understanding range objects used with .delete/.resize/.offset methods

    Can you explain in words and sentences what you're trying to do, without reference to code?

    EDIT: It is usually true that in deleting things, you work from bottom to top. Otherwise references get very confusing.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Understanding range objects used with .delete/.resize/.offset methods

    Sorry for the confusion and thanks for the response. I'll break it down...


    First, I want to /delete one cell using a range object and a .delete method.

    I step through this simple code on a workbook with content in rows 4 & 5 only and I get an output from MsgBox() describing the row/column:
    Column: 1
    Row: 4
    ...which verifies rng is set to column 1 and row 4. But when the very next line executes: rng.delete, Column 1, row 5 is deleted.

    Please Login or Register  to view this content.
    Recent Edit: I get the same result if I replace rng.Delete. with ws.Cells(rng.row, rng.Column).Delete
    Last edited by joe31623; 01-21-2016 at 12:17 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Understanding range objects used with .delete/.resize/.offset methods

    I'm not looking at your code, I'm looking for a lucid explanation of what you're trying to do.

  6. #6
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Understanding range objects used with .delete/.resize/.offset methods

    I'm trying to delete a cell using a range object and .delete method.

    Could you please elaborate on why/how references get confusing when working from top to bottom? That may be a clue...
    Last edited by joe31623; 01-21-2016 at 12:34 PM.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Understanding range objects used with .delete/.resize/.offset methods

    Please Login or Register  to view this content.
    Does that do what you would expect?
    Last edited by shg; 01-21-2016 at 01:06 PM.

  8. #8
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Understanding range objects used with .delete/.resize/.offset methods

    shg,

    I didn't understand how Range.Delete worked until now and it's now clear that when I delete ranges, I want to start from the bottom and work my way up.

    I'll work through the rest of my problem, but now my issues will probably be as obvious as... well -- "Bob's your uncle".

    Thank you very much for your help.

    Joe

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Understanding range objects used with .delete/.resize/.offset methods

    Bingo.

    You're welcome.

+ 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] Copy range of cells with Offset/Resize
    By frankie666 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-28-2013, 06:56 AM
  2. Objects, Properties and Methods
    By noclass1980 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2012, 06:34 AM
  3. Objects, Properties and Methods
    By noclass1980 in forum Excel General
    Replies: 0
    Last Post: 10-09-2012, 02:33 AM
  4. Can Resize and Offset be used on a range at the same time?
    By BeefNoodleSoup in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-28-2011, 06:56 AM
  5. select range using offset or resize property
    By longhorn23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2010, 06:16 PM
  6. Reference for all objects, props, methods
    By Balachan56 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-19-2009, 12:04 PM
  7. Listing an objects available methods and parameters
    By Tristan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2007, 12:11 AM
  8. Offset Method and Interpreting Absolutes in Range Objects
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-08-2006, 07:15 PM

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