+ Reply to Thread
Results 1 to 3 of 3

Use of variables calculated in a R1C1 formula in VBA

  1. #1
    Registered User
    Join Date
    06-06-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    2

    Use of variables calculated in a R1C1 formula in VBA

    Dear all,

    I would like to use variables in a sumif formula in my VBA code in order to be able to change the criterias.

    In fact, I would like for each new row (i) and each new column (j) to change the reference

    I used therefore a R1C1 formula but obtain a type mismatch error message.

    I guess the problem might come from the calculation (j-36) but I am not sure.

    The goal of the calculation is to change column in the reference sheet each time I change a column in the formula sheet

    My code is the following:

    Please Login or Register  to view this content.
    Does anybody have an idea on that?

    Thanks a lot beforehand,

    Kind regards,

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

    Re: Use of variables calculated in a R1C1 formula in VBA

    The code you're using can be optimised (to minimise iteration), however, the formula itself is a little odd - particularly the SUMIF

    Assume G2 is R03 and this is the first column iteration (eg Col AM), your formula in A1 ref style seemingly reads:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The above is the basis for my confusion as the result will simply be Kalendar!C51 given the multiplier will by definition be 1

    Generally speaking the advantage of using R1C1 notation is that you don't need to iterate and can apply the formulae en masse with relative references. Ignoring validity of your formula - we can recreate the same without the column iteration as per below:

    Please Login or Register  to view this content.
    Of course it's not clear which sheet is active when the above code is being applied and whether or not Kalendar is the same sheet as that holding the formulae results - I am assuming not given iteration

    Note; there are other elements of the above code I might be inclined to modify - above is for illustrative purposes only (re: negating need for column iteration by using a relative R1C1 reference e.g. [-36])

  3. #3
    Registered User
    Join Date
    06-06-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Use of variables calculated in a R1C1 formula in VBA

    Hi DonkeyOte,

    Thanks for the answer. I tried thinking it further and as I went through the many conditions I had to set, here is what I obtained

    Please Login or Register  to view this content.
    It works now. I guess the format is not the most efficient in the world since it takes some time to run.

    The problem is that the other sheet "Kalendar" is different sheet with a different format.

    Anyway, thanks a lot for your disponibility

    Kind regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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