+ Reply to Thread
Results 1 to 15 of 15

relative cell address in vba array formulas

  1. #1
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    relative cell address in vba array formulas

    I'm trying to program my array formula into a column of cells using vba, but I'm finding where I want a relative row address I'm getting an absolute address, always 6. Can anyone help me with this please?

    I currently have
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jlt199; 01-23-2018 at 11:51 AM.

  2. #2
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: relative cell address in vba array formulas

    Using R1C1 notation, square brackets denotes relative references and omitting brackets constitutes an absolute reference.

    So, for ex:

    In your formula RC[-1] would be a relative reference regarding the column being 1 to the left of the current cell in which the formula is placed, ie: if the formula was in C2, this reference would be B2.

    On the other hand RC-1 likely isnt even a valid entry since there are no negative columns, as this form is saying current row the formula is in but absolutely reference the -1 column (column to the left of column A, which isnt a thing)

    https://bettersolutions.com/excel/fo...1-notation.htm
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  3. #3
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    I'm sorry Zer0Cool, I don't understand what it is you're trying to say. If I change .FormulaArray to .Formula then I get the correct row reference, so I think the problem is an intricacy of .FormulaArray Perhaps they can't handle R1C1 notation?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: relative cell address in vba array formulas

    If you apply FormulaArray to a multiple cell range, it’s the equivalent of selecting all those cells, typing the formula and then pressing Ctrl+ Shift+Enter. You either need to use FormulaArray on the first cell only, and then use Filldown or Autofill to copy the formula down, or you need to refer to the entire range (“R6C4:R” & lastrow & “C4”) rather than just one row with RC4.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    Thanks all, I think I've got it

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: relative cell address in vba array formulas

    It might be helpful to do a macro recording whilst manually putting in exactly what formula, or formulas that you want, then take a look at what the macro recorder gives you for formulas ( and everything else ) in the recorded code - VBA does "R1 C1" stuff



    Edit: If you do that , remember that
    R
    is the same as
    R[0]
    but personally I would replace any R from the recorded code with R[0] - just a personal preferance to remind me that it is a relative reference
    Last edited by Doc.AElstein; 01-19-2018 at 01:05 PM. Reason: The R[0] stuff
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  7. #7
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    Any ideas as to why my solution is SO SLOW and how I might speed it up?

    Many thanks

  8. #8
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: relative cell address in vba array formulas

    Quote Originally Posted by jlt199 View Post
    Any ideas as to why my solution is SO SLOW and how I might speed it up?
    Depends on what you consider slow (how long does it take you to run it) vs what your macro is doing. The sample you gave is a very small data set, is your actual file a much larger dataset? If your actual file is larger, how much data are we talking about and is your code any different than in your sample?

    EDIT: a glance at your code and I notice a few things.
    • You have declared variables you are not using (serial, tooltype are unused variants)
    • Your method for finding last row and last column is likely a pretty slow method for doing so (via Find method using a wildcard as it evaluates each cell)
    • If the sheet on which the named ranges are is static it is likely better off creating the named ranges using a dynamic named range so it self adjusts instead of doing it via a macro

    You may consider adding screenupdating off/on to your code to speed it up as well.

    Also, I am unclear on why you need the formula in all those cells as it always returns the same answer in all of them. The formula itself could likely be more efficiently written however I am not entirely sure what its intended goal is.

    Otherwise I am not seeing anything that stands out as a chance to speed up your code. If I had to guess your last row/column lines are likely the biggest room for improvement as find can be slow on large data sets, especially with wildcards and especially since there are many alternative ways of determining last row/col
    Last edited by Zer0Cool; 01-19-2018 at 03:31 PM.

  9. #9
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    Thanks for your reply Zer0Cool, my macro was around 1-2 seconds before I added the array formula. As soon as I added that it went up to taking ~15 seconds.

    Once the macro has finished, filtering the raw data table takes an age now too, since adding the array formula

    The array formula is needed in ~2% of cases where the serial has been used in both types of tooltype - it finds the most commonly used tooltype

    Undeclared variables are a mistake in copying and pasting my code into the sample workbook, they are used in the actual thing.

    Dynamic named ranges are a good ides, thanks

  10. #10
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: relative cell address in vba array formulas

    So it sounds like its likely the array formula adding most of the time in the form of calc time.

    You can in your code toggle to manual calculations and at the end toggle back to automatic. This should at least speed up the macro run time.

    As for after the macro, its most likely the array formula at fault. How much data are we talking about filtering roughly (10 columns x 1000 rows, 10000 rows, etc)? Whats the size of your file in KB or MB? Does filtering with manual calculation turned on take a long time as well (Important to know this!)?

    I am not sure I agree about the formula needing to be an array formula, ill see if I can work out another formula. Also, why do you need the formula in more than 1 cell on the sheet if each instance of the formula returns the exact same result? What is your formula meant to do (Im not confident it does what you want)?
    Last edited by Zer0Cool; 01-19-2018 at 06:08 PM.

  11. #11
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    Thanks, I appreciate your help

    Quote Originally Posted by Zer0Cool View Post
    Also, why do you need the formula in more than 1 cell on the sheet if each instance of the formula returns the exact same result? What is your formula meant to do (Im not confident it does what you want)?
    The result is only the same in each cell because I chose a poor range of data to copy across, sorry for that.

    For each row of data the tooltype used is either tethered or ILI. Each serial number is likely to show up several times in the data set (several rows). What I intended was to find the most frequently used tooltype for each serial number

    Thanks again

  12. #12
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: relative cell address in vba array formulas

    Quote Originally Posted by jlt199 View Post
    What I intended was to find the most frequently used tooltype for each serial number
    Ah ok that explains filling it down the list. So the expected result is its either "tethered" or "ILI" on each line, according to which has the most occurrences of the serial number from the current row?

  13. #13
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    Quote Originally Posted by Zer0Cool View Post
    Ah ok that explains filling it down the list. So the expected result is its either "tethered" or "ILI" on each line, according to which has the most occurrences of the serial number from the current row?
    That's right, at least that's what I'm hoping for

  14. #14
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: relative cell address in vba array formulas

    See attached sample using regular non-array formulas. Presuming I understood your intended results it should be much faster and more accurate (yours was totally not working, each one in your sample returned the IFERROR error value).

    I left your formulas in for comparison.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    03-19-2010
    Location
    Calgary, Canada
    MS-Off Ver
    Office 2013, Office 365 Pro Plus
    Posts
    182

    Re: relative cell address in vba array formulas

    Yes, I was just trying to edit mine for another purpose and the more I got into it, the more I realised it was wrong!

    Thanks for your help

+ 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] Get cell value relative to Array-Max
    By ladroru in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-06-2016, 02:15 AM
  2. Make part of address indirect and keep rest of address relative?
    By OldManExcellor in forum Excel General
    Replies: 1
    Last Post: 01-29-2016, 06:07 AM
  3. Store array of relative cells in a cell
    By Johnado in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-24-2014, 02:50 AM
  4. Copying from textbox to relative cell in array
    By kuraitori in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2008, 08:27 PM
  5. Relative References in Array Formulas - VBA
    By NBVC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2007, 12:01 PM
  6. what is difference between absolute address and relative address?
    By what is difference between absolute addr in forum Excel General
    Replies: 1
    Last Post: 07-22-2006, 03:25 AM
  7. relative cell address
    By Harlen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2005, 09: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