+ Reply to Thread
Results 1 to 8 of 8

Coding a Formula in Macro

  1. #1
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Exclamation Coding a Formula in Macro

    Hi, everyone! I hope you have a good day.

    I have this problem that I have to put a formula in a button in VBA, and I've tried all of the ways here https://www.automateexcel.com/vba/formula-formular1c1 but nothing works and always give me the error from Macro.

    My original code is:

    Please Login or Register  to view this content.
    maxMarker is a variable that could change, hence why I put it as "C" & (maxMarker + 4).

    I want to get the value from cell C2 and I got that code from Record Macro, but since [-20] means 20 from the current active cell, and so whenever the values change, the generated formula from the button changes and it is no longer from C2.

    The formula I want should be =IF(ISBLANK(C2),"",VLOOKUP(C2,ASetup,10,0)) but every time I put it there it's always giving me errors. I've tried the Range("C" & (maxMarker + 4)).Formula, the R1C1 one and it's always giving me errors. Is there a another way to put the =IF(ISBLANK(C2),"",VLOOKUP(C2,ASetup,10,0)) there?

    I'd really, really appreciate it if anyone would kindly help me on this. Thank you so much, stay safe always!

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Coding a Formula in Macro

    If it should always look at C2 try
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Coding a Formula in Macro

    Hi, Fluff13! Thank you for answering!

    Ah, I've tried that, but it locks the C column... whereas I don't want to lock it so that it could still be C2 because the formula needs to be dragged to other cells...

    Is there any other way? Thank you!

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Coding a Formula in Macro

    Is there any other way?
    Yes there is, but it will need more information.
    Can you attach a file

  5. #5
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Coding a Formula in Macro

    Here's the file, I've tried to simplify it from my original file, but the focus should be on the remaining two sheets.

    The codes are in Module 1 and I've marked the formula code with '/////////// formula <- here!

    When it's working, the button should be able generate the result without N/A.

    Thank you so much!
    Last edited by nettadecoco; 05-06-2022 at 09:06 AM.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Coding a Formula in Macro

    Thanks for that, unfortunately I cannot test this as your code fails, but try
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-03-2022
    Location
    London, England
    MS-Off Ver
    Ms. Office 2013
    Posts
    79

    Re: Coding a Formula in Macro

    Hi, Fluff13, yes, it works!

    Thank you so much for your replies! I hope you have a good day!

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Coding a Formula in Macro

    Glad to help & thanks for the feedback.

+ 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] In need of help regarding combo box coding and button coding (Access form project)
    By mailblade in forum Access Tables & Databases
    Replies: 2
    Last Post: 01-09-2016, 01:34 AM
  2. macro coding help (i have no background in coding)
    By notgoodenough in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-05-2014, 10:22 PM
  3. [SOLVED] Vb macro coding for transpose - complete coding?
    By Dharani Suresh in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-02-2013, 11:16 PM
  4. [SOLVED] Vb macro coding for transpose - complete coding?
    By Dharani Suresh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-02-2013, 05:04 AM
  5. Implant macro coding into ASP coding
    By Sam yong in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2005, 06:05 AM
  6. [SOLVED] Help please with coding a macro
    By useR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2005, 05:05 PM

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