+ Reply to Thread
Results 1 to 5 of 5

VBA mixed references

  1. #1
    Registered User
    Join Date
    09-10-2015
    Location
    London
    MS-Off Ver
    365 at work, 2016 at home
    Posts
    79

    VBA mixed references

    I need a very simple macro which when activated copies the value in the b col in the current row. My problem is that I need to be able to activate the macro regardless of which cell is currently active so the col ref needs to be absolute, but the row ref needs to be relative. In formulae to be replicated to other cells it's very easy: $B1, $B2 etc, is it possible in VBA? if so how?

    I've found a couple of things that mention mixed references but they all refer to one reference that's entirely relative working with another that's entirely absolute, I want one reference that has one of each element.

    Thanks muchly.

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA mixed references

    Something like this if I get what you try to achive

    Please Login or Register  to view this content.
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    09-10-2015
    Location
    London
    MS-Off Ver
    365 at work, 2016 at home
    Posts
    79

    Re: VBA mixed references

    not quite but
    Please Login or Register  to view this content.
    does the job.
    Got the vast majority from yours obviously, thanks muchly.
    Just so I'm sure I understand how it works, so I can replicate it for future projects that may be slightly different.
    Is the
    Please Login or Register  to view this content.
    telling it to perform the
    Please Login or Register  to view this content.
    operation from the first column? or have I missed it?
    Thanks again.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA mixed references

    The EntireRow property can be useful


    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA mixed references

    Please Login or Register  to view this content.
    is the same as

    Please Login or Register  to view this content.
    So
    1. With allows to skip repeating object reference
    2. ActiveCell.Offset (rowsoffset, columnsoffset) tells that you want to work with a cell that is offset from the curent active cell, e.g. 0 rows and some columns offset from the active cell in our case
    3. offset of 2-ActiveCell.Column columns tells that you want to work with column B. E.g. if the active cell is E5 then ActiveCell.Column=5 and the columnsoffset =2-5=-3. So you want to work with the cell that is 3 columns to the left of the active cell, in our case that is column B

+ 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. Mixed references in VBA formulas
    By McNultyK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2011, 06:13 PM
  2. Copying formulas with mixed references
    By Duke Carey in forum Excel Formulas & Functions
    Replies: 30
    Last Post: 09-06-2005, 05:05 PM
  3. Copying formulas with mixed references
    By TMcMillin in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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