+ Reply to Thread
Results 1 to 5 of 5

Relative Macro

  1. #1
    Forum Contributor
    Join Date
    03-25-2011
    Location
    London, England
    MS-Off Ver
    office 2021
    Posts
    318

    Relative Macro

    Hi I am trying a lesson to learn about VBA. Not sure if I should ask this here. I have been doing it again and again for hours. I also appreciate that left in is all the Microsoft stuff which could be stripped out. I have left it in so as to show that the code has not been messed with.

    I have uploaded an excel file “ExcelForum100”

    There are two macros
    Ctrl-shift-L which is a simple absolute macro and runs perfectly.
    Ctrl-Shift-A which is a simple Relative macro which I cannot get running.
    Sheet one is from a shorter list and is what I get from the absolute macro.
    Sheet is a slightly larger list to demonstrate the flexibility of a relative macro. You will see it is missing the total.
    Sheet three is the file used to create the macro which works fine.
    Honestly I am totally flummoxed.

    This is a course I am doing so as to be able to understand the directions from you so despite being an odd request is actually related to here….I hope.

    The line which is stopping it all seems to be 5 from the bottom
    “ActiveCell.Offset(-1, -3).Range("A1").Select”
    Please Login or Register  to view this content.
    Mark
    Attached Files Attached Files

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Relative Macro

    What range are you trying to select? A1?

    You can't offset to the left of column A and the range collection is not part of ActiveCell which if I had to guess was an object.

    ActiveCell.offset(-1,-3).select maybe? Or Range("A1").Select?


    e/ Turns out Range is a property. But the questions remain the same. I'm guessing you're trying to offset from left of column A (there isn't a column left of A).
    Last edited by Solus Rankin; 11-12-2013 at 02:49 PM. Reason: researched for more information
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Contributor
    Join Date
    03-25-2011
    Location
    London, England
    MS-Off Ver
    office 2021
    Posts
    318

    Re: Relative Macro

    Hi Solus

    thanks for this. I was directed to an Auto complete validation which also allowed new data and i could not work out how to use it so am going back to study. Long way to go. I will study your suggestion which is most likely correct but how did it get written like that as it was generated by recording.

    Mark

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Relative Macro

    The macro recorder can record in relative if you ask it to. What I'm guessing is there was a different "starting cell" when you record then there was when you ran the macro. If you run the macro with a starting position left of where the recorded starting position (activecell) was then you run the risk of running out of columns.

  5. #5
    Forum Contributor
    Join Date
    03-25-2011
    Location
    London, England
    MS-Off Ver
    office 2021
    Posts
    318

    Re: Relative Macro

    Thanks again Solus. I have been studying the lines based on what you said earlier. Below I show what i have learnt. Actually having had to study every line has helped me enormously.

    Please Login or Register  to view this content.
    hope this is useful to anyone who has had my problem. In all honesty I am still not sure how i created a -1 for the column.
    Again thanks. Pleased to make this solved.

    Mark

+ 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. I need help with making a macro relative to a selection field within the macro
    By namer98 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-30-2013, 11:30 AM
  2. macro relative addressing
    By LonnieP in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2010, 11:57 AM
  3. relative value in macro
    By Janett in forum Excel General
    Replies: 2
    Last Post: 04-04-2006, 12:45 PM
  4. macro vba relative references
    By aut1jlt in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-20-2005, 02:06 PM
  5. [SOLVED] Relative reference in macro
    By Ricki Miles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2005, 05:06 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