VBA for automatic formula calculation in the range of cells after cell value input

fotodj

New Member
Joined
Jul 19, 2014
Messages
36
Office Version
  1. 2016
Platform
  1. Windows
I am looking for the code working on change of value basis, which does the following: after I type number in col A, column B would show 5% tax calculation and column C total with tax,
I know that I can use formula in Col B =A1*0.05 and =A1+B1 in Col C but I have to copy the formulas and drag it down every time new row is added, I would like to automate that process...
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Assuming you have formulas in there already, starting in row 1. You can paste this macro into the sheet (not in a module).

If a change is made in column A it will copy the formulas in B1 and C1 down to the last row.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
    Dim sht As Worksheet
    
    Set sht = ActiveWorkbook.ActiveSheet
    Set KeyCells = Range("A:A")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then
    lastrow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
    Range("B1:C1").Copy Range("B1:C" & lastrow)
       
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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