+ Reply to Thread
Results 1 to 4 of 4

Trouble using Excel VBA OFFSET function

  1. #1
    Registered User
    Join Date
    05-20-2014
    Posts
    1

    Trouble using Excel VBA OFFSET function

    I have an Excel workbook with numerous sheets entitled "Week1", "Week2", "Week3" ... "Week7". Each week, I input the customers IDs of people buying my product in column C, and -- as I am interested knowing if these are return customers or if they are new ones -- I have written a function to check if the customers I input in Week2-Week7 are new customers or whether they have previously bought my product.

    To that end, I have developed the following formula which I input into column F for Week2:

    =IF(COUNTIF(Week1!$C$3:$C$100,C3)>=1,"Old","New")
    With the relevant part of "Week1" looking like:

    _|-----C-----|-----F-----|

    3| ValPot1 | *blank* |
    With the relevant part of "Week2" looking like:

    _|-----C-----|-----F-----|

    3| ValPot1 | Old |
    Now, although this works well, it becomes rather cumbersome by the Week7, when I have to use the following function:

    =IF(OR(COUNTIF(Week1!$C$3:$C$100,C3)>=1,COUNTIF(Week2!$C$3:$C$100,C3)>=1,COUNTIF(Week3!$C$3:$C$100,C3)>=1,COUNTIF(Week4!$C$3:$C$10>0,C3)>=1,COUNTIF(Week5!$C$3:$C$100,C3)>=1,COUNTIF(Week6!$C$3:$C$100,C3)>=1),"Old","New")

    Consequently, I've been trying (unsuccessfully) to use the following VBA function:

    Please Login or Register  to view this content.

    By incorporating it in sheet "Week2", cell F3, in the following manner:

    =IF(COUNTIF(SHEETOFFSET(-1,$C$3):SHEETOFFSET(-1,$C$100),C3)>=1,"Old","New")
    In effect, I'm just replacing my previous worksheet reference (of Week1!$C$3:$C$100) with my new SHEETOFFSET function....

    Unfortunately, this doesn't work, and simply returns a #VALUE! error. What am I doing wrong, and how can I fix my function?
    Last edited by JBeaucaire; 05-20-2014 at 10:29 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Trouble using Excel VBA OFFSET function

    Here's my take on that idea...

    Please Login or Register  to view this content.
    It's used in a cell exactly like COUNTIF to get a numeric answer, but it counts the values on every sheet PRIOR to the sheet where the formula exists. For example:

    =CountIfPriorSheets(A1:A20, "Cat")


    Now, you can wrap that in your ealier test for a "old/new" response:

    =IF(CountIfPriorSheets(A1:A20, "Cat")>0, "Old", "New")
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Trouble using Excel VBA OFFSET function

    Here's a link to the published code and a sample workbook.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Trouble using Excel VBA OFFSET function

    I think your life would be much easier if you kept all the data on one sheet and added a column to indicate week number. The formulas would then be pretty simple.
    Everyone who confuses correlation and causation ends up dead.

+ 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. trouble with OFFSET function for updating a graph
    By JeepGuy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-11-2011, 10:11 AM
  2. Having trouble with OFFSET Function
    By brady in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-18-2007, 06:16 PM
  3. offset formula trouble
    By Don Juan in forum Excel General
    Replies: 1
    Last Post: 09-20-2006, 08:43 PM
  4. offset trouble
    By Don Juan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-12-2006, 08:33 AM
  5. [SOLVED] Offset Function Trouble, Please Help
    By Rabbit in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-27-2006, 09:10 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