How to carry over functions/Formulas into new rows while using the command button macro to add new rows?- Please Help:)

JSoto74

New Member
Joined
Sep 28, 2020
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hello all,

I'm new here and just starting to dive into the more complicated world of excel :)

I created a command button via VBA to add a new row below to the top of my list for entry but now having issues with the functions/formulas not copying over. For example a simple =(??) to mirror another cell in the new row or a function such as =IF(COUNTA(Z6:AA6)=2,"Y","N") to carry over as well. See below for what works so far for adding the new line just need some help with figuring out the rest. Please help!


Private Sub CommandButton1_Click()

Sheets("2019-2020 R&R Tracker Test").Range("A7").Select
ActiveCell.EntireRow.Insert Shift:=xlDown

Sheets("2019-2020 R&R Tracker Test").Range("A7:AK7").Select
Selection.Borders.Weight = xlThin

End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Still having an issue. Seem the last macro is in red due to having this input incorrectly. See below of what I have so far...please help!

Private Sub CommandButton1_Click()

Sheets("Food & Beverage").Range("A7").Select
ActiveCell.EntireRow.Insert Shift:=xlDown

Sheets("Food & Beverage").Range("A7:AJ7").Select
Selection.Borders.Weight = xlThin

Sheets("Food & Beverage").Range("r7").Select
ActiveCell.Formula = "=(e7)"

Sheets("Food & Beverage").Range("s7").Select
ActiveCell.Formula = "=(f7)"

Sheets("Food & Beverage").Range("s7").Select
ActiveCell.Formula = "IF(COUNTA(Z6:AA6)=2,"Yes","No")"
 
Upvote 0
You need to double-up on the quotes inside the formula, like
VBA Code:
"=IF(COUNTA(Z6:AA6)=2,""Yes"",""No"")"
You are also missing the = sign.
 
Upvote 0
You can also clean up that code like
VBA Code:
With Sheets("Food & Beverage")
   .Range("A7").EntireRow.Insert Shift:=xlDown
   .Range("A7:AJ7").Borders.Weight = xlThin
   .Range("r7").Formula = "=(e7)"
   .Range("s7").Formula = "=(f7)"
   .Range("s7").Formula = "=IF(COUNTA(Z6:AA6)=2,""Yes"",""No"")"
End With
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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