+ Reply to Thread
Results 1 to 3 of 3

Combine a formula from texts in different cells by VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2020
    Location
    Oss, Netherlands
    MS-Off Ver
    Office 365 ProPlus
    Posts
    3

    Combine a formula from texts in different cells by VBA

    I would like a macro to create a cell containing a formula like:

    ='X:\Documents\Database\Database files[DatafileB.xlsm]computed'!A3

    (as is visible in the example picture and xlsx file: )
    MacroCombineValuesFormula.jpg

    So that this cell uses the values of:

    Cell B1: The indicated cell (in this example: A3)
    Cell B2: The indicated tab (in this example: computed)
    Cell B3: The indicated xlsm-file name (in this example: DatabasefileB.xlsm)
    Cell B4: The indicated file path (in this example: X:\Documents\Database\Database files)
    How can I make a macro that creates that formula in cell B5?

    I know I can make that formula by concatenate or using the & signs, but then it just sees it as a text and not the formula that does the desired job.

    Thanks in advance.



    Regards, Kenny
    Attached Files Attached Files

  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,863

    Re: Combine a formula from texts in different cells by VBA

    Note if the file and directory (also sheet in a file) exist (you have some discreptancies in the description) and the code:
    Range("B5").Formula="='" & Range("B4") & "[" & Range("B3") & "]" & Range("B2") & "'!" & Range("B1")
    is doing the job.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    03-25-2020
    Location
    Oss, Netherlands
    MS-Off Ver
    Office 365 ProPlus
    Posts
    3

    Re: Combine a formula from texts in different cells by VBA

    Thank you very much!

    It works nice, but unfortunately it causes Excel to open a window for me to select the desired file in the right location:
    MacroCombineValuesFormulaWindow.jpg

    Is it possible to prevent this (since the filename and file path are known already?)

    Regards,
    Kenny
    Last edited by KennyKe; 03-25-2020 at 09:47 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. Replies: 11
    Last Post: 04-09-2019, 09:50 AM
  2. combine texts from multiple rows based on condition
    By saj123 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-25-2018, 02:43 PM
  3. Assemble formula from texts in other cells
    By 13gentj in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 12-19-2014, 11:00 PM
  4. [SOLVED] To average cells included texts - how to ignore texts in those cells - help please
    By PrayoonD in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-23-2014, 12:32 PM
  5. VBA to combine texts from cells to a single based on another cell value
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2013, 10:05 AM
  6. [SOLVED] combine texts from two field and then delete duplicate.
    By mshtuhin in forum Excel General
    Replies: 4
    Last Post: 07-13-2012, 11:31 AM
  7. combine parts of texts from few cells into one
    By Ramzes in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-07-2010, 02:38 AM

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