+ Reply to Thread
Results 1 to 5 of 5

VBA: how to replace formula with value

  1. #1
    Registered User
    Join Date
    04-22-2021
    Location
    Munich
    MS-Off Ver
    365
    Posts
    2

    VBA: how to replace formula with value

    Hi,

    I have an issue with a VBA code.

    I have a table with a column which contains the formula.

    In the next step I need to replace the formula with the value.

    The code so far is:

    Sub Zeilennummer_2()
    '
    ' Makro1 Makro
    '

    '
    Selection.ShowDetail = True
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=ROW()-1"
    Columns("B:B").Select
    Selection.Cut
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Rechnungsnummer"
    End Sub

    How can I replace "=ROW()-1" with the value?

    Thanks

    Alexander

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: VBA: how to replace formula with value

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: how to replace formula with value

    One seldom needs: Select, Selection, Activate, ActiveCell. Just use the range directly.

    Why add a formula, you could just evaluate the formula. e.g.
    Please Login or Register  to view this content.
    Last edited by Kenneth Hobson; 04-22-2021 at 10:23 AM.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,520

    Re: VBA: how to replace formula with value

    Can you explain the logic of this?
    If you select a cell in row 2 (Range("B2").Select) and use the formula as you have it, the result will always be 1.
    Why use a formula? You can just use
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-22-2021
    Location
    Munich
    MS-Off Ver
    365
    Posts
    2

    Re: VBA: how to replace formula with value

    OK, I think I need to explain a bit here.
    In general, I'm pretty profund in excel but not in VBA coding.
    What I try to accomplish is that from a pivot I just want one click to open the details AND it should add a row at the beginning of the details table, counting all rows. The number of rows can vary from 1 to several hundred. So my idea was to add a macro that simply does this and it worked. However, in the last step I need to replace the formular with the value. However, I cannot select the whole column and past value. I get an error back (because the table is formatted as an excel table).

    When I use the formular, it completes all rows from the first to the last row, no matter whow many rows I have.

    I used the macro recorder but I cannot replicate the last step of the macro on other sheets because it references to "sheet x".

    It's a very simply task but with no coding knowledge, I don't just how to select the cells with the formular and have it replaced by the number.

    Thanks

    Alex

+ 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. Looping thru rows and copy cell values from "Inputs" sheet to "Output" sheet
    By hariexcel1987 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2015, 11:32 PM
  2. Script not copying data from "Emails" sheet to "New Sheet" - Run time error: Object
    By methuselah90 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2014, 03:22 PM
  3. [SOLVED] Copy sent to "History Sheet" everytime the Active X button is pressed.
    By Spreadlover in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-26-2013, 08:40 PM
  4. [SOLVED] Copy range from hidden sheet to active sheet if cell ="Some text"
    By pjbassdc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2013, 01:19 AM
  5. Replies: 3
    Last Post: 05-31-2013, 05:16 AM
  6. [SOLVED] Macro to look up and down from the active cell, copying the active "section" of the sheet
    By mikkola in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-12-2013, 07:21 PM
  7. [SOLVED] Macro to insert a sheet "CLS" after the active sheet
    By gokzee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-04-2012, 11:14 PM

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