Results 1 to 12 of 12

How to write VBA for Excel function?

Threaded View

  1. #1
    Forum Contributor VAer's Avatar
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    803

    How to write VBA for Excel function?

    For example, Activesheet.Cells(15, 18).Value = "MSFT", where 18 is column R

    I would like to write ActiveSheet.Cells(16, 18).Formula = "=STOCKHISTORY(ActiveSheet.Cells(15, 18).Value,TODAY()-30,TODAY())", something like that, how to write syntax correctly? There is error in my code, it turns out to be =@STOCKHISTORY(@ActiveSheet.Cells(15, 18).Value,TODAY()-30,TODAY()) Actually, I want Cell R16 turn out to be = STOCKHISTORY("MSFT",TODAY()-30,TODAY()), but I cannot use MSFT directly, how to make Activesheet.Cells(15, 18).Value as part of code.

    I need to write it in this way, since there are a list of companies, I have to write a VBA loop. Cells(15, 18), Cells(15, 21), Cells(15, 24), Cells(15, 27), ........

    To make my question clear: At the end, it should look something similar to attached screenshot, and I would like to write the function =STOCKHISTORY(ActiveSheet.Cells(15, 18).Value,TODAY()-30,TODAY()) in VBA code. How?

    Thanks.
    Attached Images Attached Images
    Last edited by VAer; 09-01-2021 at 12:27 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Write A+B=B+A with Excel Function
    By Yami_Excel in forum Excel General
    Replies: 4
    Last Post: 11-15-2019, 06:19 AM
  2. [SOLVED] Write Sub procedure to format excel and write case/if statement to text file
    By vbronton in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-06-2018, 08:26 AM
  3. Excel hangs when trying to use addfromstring function to write a macro
    By gows1982 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 03:29 AM
  4. How to write Macros function to open other Excel files?
    By AP Accountan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2013, 12:52 PM
  5. Replies: 10
    Last Post: 12-10-2012, 03:26 PM
  6. How do I write this Function using Excel's IF
    By Unsafe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2007, 05:42 PM
  7. [SOLVED] How to write IF function in Excel 2000 when there are two conditi.
    By Dajana in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-26-2005, 11:06 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