Convert a foormula to a value in a macro.

FFlyboyy

New Member
Joined
May 3, 2019
Messages
3
I've been researching thisbut none of the answers I found seemed to make sense in what I am doing.

I have the following code:


' find last row
findlastrow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
lastrow = findlastrow
lastrow = lastrow - 1



' set totals row
totalrow = lastrow + 1

' Sum purchases, international, roaming and other charges and credits
Columns("R:R").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("R1").Select
ActiveCell.FormulaR1C1 = "Other Chgs & Creds"
Range("R2").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
Range("R2").Select
Selection.AutoFill Destination:=Range("R2:R" & lastrow), Type:=xlFillDefault
Range("R2:R" & lastrow).Select


Columns(17).EntireColumn.Delete

The "Sum Purchases inserts a column after collumn Q and then runs a formula to total columns N-Q.

I need to convert the column with formula (column R) to values so when I delete N-Q the totals will be there.

i wrote this about 3 years ago and havent done much scripting since so I get lost easliy. Any help mucj appreciated.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Maybe...

Code:
Sub FFlyboyy()
    ' find last row
    findlastrow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
   
   lastrow = findlastrow - 1

    ' set totals row
    totalrow = lastrow + 1

    ' Sum purchases, international, roaming and other charges and credits
    Columns("R:R").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("R1").Value = "Other Chgs & Creds"

    With Range("R2:R" & lastrow)
        .FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
        .Value = .Value
    End With

    Columns(17).EntireColumn.Delete
End Sub

Btw isn't totalrow the same as findlastrow?
 
Last edited:
Upvote 0
Hi & welcome to MrExcel
How about
Code:
Sub FFlyboyy()
   Dim UsdRws As Long
   UsdRws = Cells.Find("*", , , , xlByRows, xlPrevious, , , False).Row
   Columns("R:R").Insert
   Range("R1").Value = "Other Chgs & Creds"
   With Range("R2:R" & UsdRws)
      .FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
      .Value = .Value
   End With
   Columns(17).Delete
End Sub
 
Upvote 0
Thanks, I'll give that a try.

I loaded the findlastrow into a variable to make it easier to point to. Lastrow to me is the last row of the detail cells. Totalrow is the row with well, the totals.
 
Upvote 0
If creating another variable makes it easier for you then it is all good as it doesn't do any harm :cool:
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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