+ Reply to Thread
Results 1 to 4 of 4

Replacing placeholder letters with formulas in a macro

  1. #1
    Registered User
    Join Date
    01-09-2023
    Location
    Watford
    MS-Off Ver
    Version 2202 Build 16.0.14931.20858
    Posts
    16

    Replacing placeholder letters with formulas in a macro

    Hello, I am very much new to macros. I recorded the following macro:

    Please Login or Register  to view this content.
    In the activecell.formula part, I want to replace my placeholder formula (=R[-6]C) with a different formula:

    =(TEXTJOIN("",TRUE,IFERROR((MID(INDEX(INDIRECT($C9&"!$A:$R"),MATCH(INDEX('Role Convertor'!$C:$C,MATCH(AZ$6&AZ$8,'Role Convertor'!$A:$A&'Role Convertor'!$B:$B,0)),INDIRECT($C9&"!$A:$A"),0),MATCH("*"&$B9&"*",INDIRECT($C9&"!$1:$1"),0)),ROW(INDIRECT("1:"&LEN(INDEX(INDIRECT($C9&"!$A:$R"),MATCH(INDEX('Role Convertor'!$C:$C,MATCH(AZ$6&AZ$8,'Role Convertor'!$A:$A&'Role Convertor'!$B:$B,0)),INDIRECT($C9&"!$A:$A"),0),MATCH($B9,INDIRECT($C9&"!$1:$1"),0))))),1)*1),""))/100)*VLOOKUP(LEFT(INDEX(INDIRECT($C9&"!$A:$R"),MATCH(INDEX('Role Convertor'!$C:$C,MATCH(AZ$6&AZ$8,'Role Convertor'!$A:$A&'Role Convertor'!$B:$B,0)),INDIRECT($C9&"!$A:$A"),0),MATCH($B9,INDIRECT($C9&"!$1:$1"),0)),3)&"/EUR",'Currency Conversion Rates'!$A:$B,2,FALSE)

    When I directly paste it in, I get an error. I'm assuming it's something to do with the R1C1 format, but I'm not sure how to change this (when typing in my formula, I typed it in as =AZ4 - not sure why it switched to RC format).

    How can I fix this?

    Thanks a lot
    Last edited by hotdeaths; 03-31-2023 at 04:33 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Replacing placeholder letters with formulas in a macro

    Open the file.
    Write desired formula in AZ9.
    Make sure AZ9 is selected (after writing formula an accepting with e+Enter, probably AZ10 will be active so move one cell up).
    Open VBE (Ctrl+F11) and in immediate window (if you don't see it use Ctrl+G) write:
    Please Login or Register  to view this content.
    you will get the formula written in desired format


    You may also use just .formula not .formula r1c1

    note that any double quote in formula text shall be doubled so try (no sample file so not checked it out):


    Please Login or Register  to view this content.
    PS. Please edit your post and use CODE tags around your code
    Last edited by Kaper; 03-31-2023 at 04:27 AM.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    01-09-2023
    Location
    Watford
    MS-Off Ver
    Version 2202 Build 16.0.14931.20858
    Posts
    16

    Re: Replacing placeholder letters with formulas in a macro

    Hey Kaper,

    Thanks for the response. The selection formula method did not work because I had text as part of an indirect (Excel could not detect these as references, and therefore did not convert them).

    However, using .formula and double quotations has almost worked - I am facing 1 more slight hurdle. When the formula is entered, sheet references (those that are not part of an indirect) have an [at sign] (key on my keyboard is broken - the sign used for emails)
    placed at the beginning. This breaks the formula. How can I prevent this?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Replacing placeholder letters with formulas in a macro

    Quote Originally Posted by hotdeaths View Post
    In the activecell.formula part, I want to replace my placeholder formula (=R[-6]C) with a different formula:

    =(TEXTJOIN("",TRUE,IFERROR((MID(INDEX(INDIRECT($C9&"!$A:$R"),MATCH(INDEX('Role Convertor'!$C:$C,MATCH(AZ$6&AZ$8,'Role Convertor'!$A:$A&'Role Convertor'!$B:$B,0)),INDIRECT($C9&"!$A:$A"),0),MATCH("*"&$B9&"*",INDIRECT($C9&"!$1:$1"),0)),ROW(INDIRECT("1:"&LEN(INDEX(INDIRECT($C9&"!$A:$R"),MATCH(INDEX('Role Convertor'!$C:$C,MATCH(AZ$6&AZ$8,'Role Convertor'!$A:$A&'Role Convertor'!$B:$B,0)),INDIRECT($C9&"!$A:$A"),0),MATCH($B9,INDIRECT($C9&"!$1:$1"),0))))),1)*1),""))/100)*VLOOKUP(LEFT(INDEX(INDIRECT($C9&"!$A:$R"),MATCH(INDEX('Role Convertor'!$C:$C,MATCH(AZ$6&AZ$8,'Role Convertor'!$A:$A&'Role Convertor'!$B:$B,0)),INDIRECT($C9&"!$A:$A"),0),MATCH($B9,INDIRECT($C9&"!$1:$1"),0)),3)&"/EUR",'Currency Conversion Rates'!$A:$B,2,FALSE)
    Untested,
    Try change to
    Please Login or Register  to view this content.
    Last edited by jindon; 03-31-2023 at 06:49 AM.

+ 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. Replacing first & last letters in text string
    By kray16 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-03-2017, 03:28 PM
  2. Replacing strings/ replacing numbers and letters
    By Insert Name in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2015, 01:15 PM
  3. Replacing date format on 200 letters
    By Daisydo in forum Word Formatting & General
    Replies: 1
    Last Post: 05-15-2014, 06:22 PM
  4. calculate value based by replacing letters with numbers
    By jbowling in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 06-16-2010, 07:14 PM
  5. replacing 2 letters in a field
    By manny1975 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-21-2007, 02:15 PM
  6. [SOLVED] Replacing capital letters
    By jezzica85 in forum Excel General
    Replies: 4
    Last Post: 02-27-2006, 09:10 PM
  7. Replacing letters for figures in formula
    By Irene in forum Excel General
    Replies: 11
    Last Post: 01-06-2006, 10:39 AM

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