+ Reply to Thread
Results 1 to 14 of 14

Using a relative or absolute? cell in formula

  1. #1
    Registered User
    Join Date
    02-20-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    92

    Using a relative or absolute? cell in formula

    Hey,

    I'm working on my first real macro - so I'm a greenhorn. I've spent a few hours trying to research a solution, but most threads are too technical for me so I'm hoping someone can really help me out.

    I am trying to use a formula that references a cell that changes day to day from when I use the macro. I need to use a formula which grabs from a cell in a non concrete location. Let me try and show you what I mean.

    From I4:I10, I need a formula like this:
    Please Login or Register  to view this content.
    The part in red is the cell I have trouble referencing. In other words, I am trying to reference a cell in a separate range, but that cell changes rows. This is probably really vague, so I'm sorry.

    Is there a way to name a cell in a range? Because the cell I'm looking for is always D2 in the range I created. But the cells with the formula are not in the range, so I'm having trouble referencing that particular cell. I appreciate any help that is offered, but please keep in mind my knowledge is extremely limited - especially with various functions, etc.
    Last edited by starcraftbud; 02-25-2009 at 09:33 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Using a relative or absolute? cell in formula

    I can't see D" in your formula at all, This is the formula that is written by your code

    =IT1*365/IQ$17*10000
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using a relative or absolute? cell in formula

    Quote Originally Posted by royUK View Post
    This is the formula that is written by your code

    =IT1*365/IQ$17*10000
    Roy I disagree, if the first formula goes into I4 the below:

    Please Login or Register  to view this content.
    Will become

    Please Login or Register  to view this content.
    starcraftbud, I'm afraid I don't quite follow what you're asking though...

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Using a relative or absolute? cell in formula

    I just put the formula into A1 to see whether the cell was actually in it.

  5. #5
    Registered User
    Join Date
    02-20-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    92

    Re: Using a relative or absolute? cell in formula

    Wow, thanks for the quick responses guys. I'll try to explain a little better or at least give more details.

    Let me first ask this question because if it can be done, it will solve all my problems.

    Can a cell in a set range be named? If I am working with a spreadsheet which varies in length, but I construct a range beneath all the information, I am looking to name a cell from my range. The cell is always
    Please Login or Register  to view this content.
    I haven't figured out how to do that. I can only name cells not in a range.

    If that will not work, let me take a step out and re-explain in a broader way what I am trying to do. As I mentioned a have a spreadsheet where the rows vary. Despite the length of the spreadsheet, I set a range of cells 2 rows beneath the last cell with information. Within the range I set, there is a cell that I am trying to reference (which is always cell D2 from the set range). I am trying to reference the cell outside of the range.

    OK, so I have my original spreadsheet and lets say cell I4 is where I'm trying to enter a formula. In Cell I4, using the formula I wrote above
    Please Login or Register  to view this content.
    The R17C[-6] part needs to be cell D2 from the set range. The column is always the same, so a relative reference to -6 is fine, but since the actual row of the cell changes, I'm not sure how to properly reference it within the formula.
    Last edited by VBA Noob; 02-21-2009 at 01:25 PM.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using a relative or absolute? cell in formula

    starcraftbud, sorry to say but I'm confused... I was waiting to see if RoyUK was going to post but I suspect like me he is confused also...

    It would be best to illustrate with a sample workbook, perhaps outline via a couple of sheets what you mean by your varying range etc and also indicate expected results.... from that we should be able to assist, as is I don't have a clue I'm afraid.

  7. #7
    Registered User
    Join Date
    02-20-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    92

    Re: Using a relative or absolute? cell in formula

    Thats OK. Its my fault I'm not explaining it very well.

    Thank you for your patience. I'll try to post a sample. I've seen other people do it before so here goes.

    OK. I attached it. I hope it works.

    Now let me give you some detail. Since I'm not at work, I only have a mangled unfinished version here, but it should still work. The macro is called 'MilReconFormat'

    When prompted at the start of the macro, please type '38' so we'll be talking about the same thing. Now, the area I need help with is column I. Notice cells I31:I35. Note how they all have D28 in the cell. This is fine and its how I want it, but if you look at the macro code, you'll see its because those cells stay relative to whatever cell the "prior day NAV" is - in this case D28. I want to get this formula to cells I5:I18. And they need to have D28.

    We are using '38', but if you observe the rest of the original spreadsheet, you will see what I mean when I meant the top part varies in row length.
    Attached Files Attached Files

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using a relative or absolute? cell in formula

    starcraftbud, I am working through your code and will post up a solution later... there's quite a bit to get through and I think you can optimise quite a bit.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using a relative or absolute? cell in formula

    Attached is a revised version of your file which I think does what you want...re: insertion of formulae into CUSIP BP's column.

    I made some changes to your code and I will list here also -- I like to see the code out in full rather than in an embedded file for reference if nothing else.

    Your first routine, I shortened to:

    Please Login or Register  to view this content.
    Your second routine I shortened to:

    Please Login or Register  to view this content.
    Your final routine I will post in a subsequent replay else it is too long !
    Attached Files Attached Files

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using a relative or absolute? cell in formula

    You final routine....

    Shortened (?!) to the below ...

    More importantly I removed a lot of your .Select statements these will slow code and you rarely need to Select anything... also where formats, formulas are common you can update in "batches" rather than processing each individually.

    Hopefully this will be useful for you going forward.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-20-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    92

    Re: Using a relative or absolute? cell in formula

    I haven't tried it yet, but I will right now. I am incredibly impressed. Like I said, this is my first macro so I'm not surprised you found a lot to fix. I'll respond after I've taken the time to go through it, but even before I do, I just wanted to say thank you.

  12. #12
    Registered User
    Join Date
    02-20-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    92

    Re: Using a relative or absolute? cell in formula

    =)

    Let me tell you - absolutely incredible. I spent hours putting that together and you very quickly made it much cleaner and resolved the problem I was having. At parts, the code you use is really difficult to follow, its a couple steps ahead of me, but your format is very nice and I can learn a lot from it.

    Additionally, I want to say that you really helped me. This macro is going to get me recognition at work and it will save people time. This will save many people about 10 minutes a day - which added up, saves hours a day. You did me a very large favor.

    I wish you luck in your job search (from your signature) - which surprises me that you are having trouble.

  13. #13
    Registered User
    Join Date
    02-20-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    92

    Re: Using a relative or absolute? cell in formula

    How do I mark this as solved? It has been solved.

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using a relative or absolute? cell in formula

    Re: SOLVED - see "How To" in the Hyperlink Options above this thread.

    In answer to your penulimate post you're welcome and I'm glad it worked for you.

    The reality is that your question could have been resolved by adding one line of code to your main Format routine, namely the penultimate line:

    Please Login or Register  to view this content.
    The reality was I had to read through the code to understand what you were trying to achieve and in doing so I figured I would update it where I felt there were gains to be had... in truth given the volume of data being processed the impact of the changes is virtually irrelevant (if noticeable at all!) but as you say you will hopefully learn from it... it's still probably not optimal but does illustrate how .Select (& subsequently Selection) is rarely required... and as you process bigger data sets you will notice the difference performance-wise of a "Select-Free" approach.

+ 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