Post the formula instead of value?

NicoLandbo

New Member
Joined
Jun 29, 2017
Messages
11
Hi,

Hope someone can help me with this. I thought it would be pretty simple to do, and I have tried alot without any luck. So now I come seeking some expertise.

Code:
Sub Explained_variance()

    Dim i As Long
    Dim BALlastrow As Long
    Dim v As Variant
    Dim LockedCell As Range
    Dim j As Long
    
    BALlastrow = Range("B" & Rows.Count).End(xlUp).Row
    
    For i = 6 To BALlastrow
        If Range("G" & i).Interior.Color <> Range("G" & i).Offset(1).Interior.Color And Range("G" & i).Interior.Color <> Range("G" & i).Offset(-1).Interior.Color Then
        Range("G" & i).FormulaR1C1 = "=IFERROR(RC[-2]/(ABS(RC[-2])),"""")"
        j = 1
        
        Else
        Set LockedCell = Range("E" & i - j)
            If LockedCell = 0 Then
            LockedCell = 0.0001
            End If
            
        With Application
            v = .IfError(Range("E" & i) / Abs(LockedCell), "")
            Range("G" & i).Formula = v
        End With
        
        j = j + 1
        
        End If
    Next i
    
End Sub

This is my sub. It works as intended, but this area in particular post the value of the formula, instead of including the formula:

Code:
With Application            v = .IfError(Range("E" & i) / Abs(LockedCell), "")
            Range("G" & i).Formula = v
        End With

Can anyone help me with what I should change in the above code?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Replace this


Code:
With Application
            v = .IfError(Range("E" & i) / Abs(LockedCell), "")
            Range("G" & i).Formula = v
        End With

By
Code:
Range("G" & i).Formula = "=IFERROR(E" & i & "/ABS(E" & i - j & "),"""")"
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,199
Members
453,022
Latest member
RobertV1609

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