+ Reply to Thread
Results 1 to 6 of 6

Clarify OFFSET Command

  1. #1
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Clarify OFFSET Command

    From a previous post I understand that the Offset parameter for my cmdADD_Click() shown below should be like (1, n). I did this change and it works well; in a lesson I follow it was set like this (0, n)

    Please Login or Register  to view this content.
    But how about the following two commands shown below, cmdDelete_Click() and cmdEdit_Click(), should I also change the Offset to (1, n) from (0, n)? When I do this change I notice no difference but perhaps I’m making a mistake. The reason I’m asking is perhaps on Delete / Edit commands this Offset parameter makes no difference?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Clarify OFFSET Command

    Too lazy to read all your code, but:

    "Offset" determines the number of cells "away" from the cell you're working with - where the first number is the offset in rows and the second number is the offset in columns.

    A few examples:
    Please Login or Register  to view this content.
    would be cell A2, since it's A1 offset by 1 row and 0 columns

    Please Login or Register  to view this content.
    would be cell B2, since it's A1 offset by 1 row and 1 column

    Please Login or Register  to view this content.
    would be cell F1, since it's 4 rows less and two columns extra.

    Please Login or Register  to view this content.
    would be cell D25, since there's only 1 number specified, excel assumes it's rows, since there's no comma

    Please Login or Register  to view this content.
    is cell X5, since it's offset 20 columns.

    I hope this clarifies things.
    Please click the * below if this helps

  3. #3
    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,443

    Re: Clarify OFFSET Command

    I think JasperD has done an excellent job of explaining the Offset property of a range.

    Here's an explanation from the horse's mouth ... but with a lot less detail For more examples, Google: excel vba offset property of range

    That said, it isn't really necessary or useful in this case . It just means that you have to work out, based on the start range and the offset, where you will be putting the data. Bit of a PItA in my opinion. Very helpful if you're looping through a range, but you're not.

    Some alternatives to compare. I'm not actually searching for the ID, I've just set a cell as the starting point for each of the options.

    Please Login or Register  to view this content.

    Regards, TMS
    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


  4. #4
    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,443

    Re: Clarify OFFSET Command

    Sorry, as an answer to the specific question.

    If you are inserting a new entry, you need to find the last row of data and add 1 to the row ... so you write the new data into an empty row. You would write .Offset(1, n)

    If you are editing or deleting an entry, you need to find the row that corresponds to that ID and edit that row. In this case, you'd write .Offset(0, n)


    Regards, TMS

  5. #5
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: Clarify OFFSET Command

    TMS you are a genius and you made my day

    I followed what you mentioned in my earlier post “Offset should ALL be (1, n) rather than (0, n) and it worked well in the ADD command but in the DELETE or EDIT command did not work and that was driving me crazy.

    Now with your excellent reply, all is fine and understood.

    Thanks so much

  6. #6
    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,443

    Re: Clarify OFFSET Command

    You're welcome.

    Did you see post #3?



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Replies: 3
    Last Post: 03-06-2015, 04:45 AM
  2. [SOLVED] How do I use a if and vlookup statement to clarify a day and time?
    By Waynej4t in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-11-2012, 04:11 AM
  3. Offset command
    By MikeTD in forum Excel General
    Replies: 6
    Last Post: 12-08-2006, 10:16 AM
  4. [SOLVED] need to clarify
    By John Sawyer in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-18-2005, 10:05 AM

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