VBA to apply formula to existing data in cells

MOB

Well-known Member
Joined
Oct 18, 2005
Messages
1,061
Office Version
  1. 365
Platform
  1. Windows
Cells AT6 to CQ "lastrow" contain numeric values, not formulae

I need a bit of code that looks in each cell, divides the value by 7, and multiplies it by the value in row 4

End result should be a value rather than a formula and if the cell was originally blank, it should remain blank

Is this easy to achieve?

TIA
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try

Code:
'cells AT6 to CQ "lastrow" contain numeric values, not formulae
'
'I need a bit of code that looks in each cell, divides the value by 7, and multiplies it by the value in row 4
'
'End result should be a value rather than a formula and if the cell was originally blank, it should remain blank
'
'Is this easy to achieve?
'




Option Explicit
Dim LastRowNo As Long
Dim FirstCol As Integer
Dim LastCol As Integer
Dim RowLoop As Long
Dim ColLoop As Long


Sub DoFormula()
'get the column values
FirstCol = Worksheets("Sheet1").Range("AT6").Column
LastCol = Worksheets("Sheet1").Range("CQ6").Column


LastRowNo = Worksheets("Sheet1").Cells(Rows.Count, "AT").End(xlUp).Row
'do formula
For ColLoop = FirstCol To LastCol
    For RowLoop = 6 To LastRowNo
        If IsNumeric(Worksheets("Sheet1").Cells(RowLoop, ColLoop).Value) = True Then
            Worksheets("Sheet1").Cells(RowLoop, ColLoop).Value = Worksheets("Sheet1").Cells(RowLoop, ColLoop).Value / 7 * Worksheets("Sheet1").Cells(4, ColLoop).Value
        End If
    Next RowLoop
Next ColLoop


End Sub
 
Upvote 0

Forum statistics

Threads
1,221,444
Messages
6,159,914
Members
451,603
Latest member
SWahl

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