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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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