+ Reply to Thread
Results 1 to 5 of 5

Auto Adjust VBA Code

  1. #1
    Registered User
    Join Date
    04-18-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    8

    Auto Adjust VBA Code

    Hey,

    Probably a really stupid question, but is there a way to make VBA code auto adjust when you change the worksheet?

    For example, my VBA code is looking into A40, but if I want to modify my sheet and add a row at A10, the VBA code will still be looking at A40, when it should be looking at A41. Its a massive pain as i've made a huge amount of coding in a workbook and need to modify it now.

    Thanks!

    Joe

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Auto Adjust VBA Code

    Hello Joe,

    To provide you a solution, you should post your workbook with before and after examples.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Auto Adjust VBA Code

    Hey Skank... (one of the better truncated names I've written to)

    Short answer: Not that I know of

    Long answer: You have two options available to you.

    1) If you have a header row/column, you can use a search function to find the old A40 record, and work off of offsets from there rather than hard coding the row position.

    2) You can set up a separate worksheet with cell contents that contain cell references that you can manually update, and use these as variables in your VBA. Like in A1, put in A40, and then in the VBA, just declare the range variable equal to the text in A1. (It makes sense to me... I hope you can follow what I'm saying)
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  4. #4
    Registered User
    Join Date
    04-18-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Auto Adjust VBA Code

    Thanks Miraun. I just wanted to know if there was a way to switch the auto adjust on in VBA.

    What i'll probably do is just name all my ranges. I'll have to make adjustments this time but won't have to anytime afterwards.

    Thanks Again!!

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Auto Adjust VBA Code

    I don't see how naming your ranges will help you if rows are not inserted, your named ranges will not grow. Is A40 or A41 your last row in your data set?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ 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