Define formula in a code

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello Experts
I am trying to add an extra column in the Edited Portal sheet within JohnnyL's code. I have edited and made some changes successfully. I want to define the formula in the code and get the result under Narration column N. The formula to be written in the code is shared below. The test workbook link is also shared below

2. Step to add Narration.xlsm
=$C$1&" "&C2&" "&$D$1&" "&D2&" "&$E$1&" "&E2&" "&$F$1&" "&TEXT(F2,"dd-mm-yyyy")&" "&$L$1&" "&L2&" "&$M$1&TEXT(M2,"dd-mm-yyyy")
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Replace the following code:
VBA Code:
    wsDestination.Columns("F:F").NumberFormat = "@"                             ' Set column to text format to prevent excel changing dates
    wsDestination.Range("A2").Resize(UBound(OutputArray, 1), UBound(OutputArray, 2)) = OutputArray  ' Display results to DestinationSheet

with:
VBA Code:
    wsDestination.Columns("F:F").NumberFormat = "@"                             ' Set column to text format to prevent excel changing dates
    wsDestination.Range("A2").Resize(UBound(OutputArray, 1), UBound(OutputArray, 2)) = OutputArray  ' Display results to DestinationSheet
'
    Dim DestinationLastRow  As Long
'
    DestinationLastRow = wsDestination.Range("A" & wsDestination.Rows.Count).End(xlUp).Row  ' Get last row used in column A of the destination sheeet
'
    wsDestination.Range("N2:N" & DestinationLastRow).Formula = "=$C$1 & "" "" & C2" & _
            " & ""  "" & $D$1 & "" "" & D2 & ""  "" & $E$1 & "" "" & E2" & _
            " & ""  "" & $F$1 & "" "" & TEXT(F2,""dd-mm-yyyy"") & ""  "" & $L$1" & _
            " & "" "" & L2 & ""  "" & $M$1 & "" "" & TEXT(M2,""DD-MM-YYYY"")"   ' Copy Narration Formula to Column N
 
Upvote 0
Solution
JohnnyL. Can you please convert the result to value in place of formulas.? I mean copy, pastespecial, values....
because I would be shifting the required rows with narration to a different sheet and the formula will show an error.
 
Upvote 0
Add the following to the end of my last posted code:
VBA Code:
'
    wsDestination.Range("N2:N" & DestinationLastRow).Copy                       ' Copy formula range into memory
    wsDestination.Range("N2:N" & DestinationLastRow).PasteSpecial xlPasteValues ' Paste just the vales back to range
    Application.CutCopyMode = False                                             ' Clear clipboard & 'marching ants' around copied range
 
Upvote 0
Just like I imagined it. Thanks JohnnyL.
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,038
Latest member
apwr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top