Including varible in formula VBA

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
333
Office Version
  1. 2010
Platform
  1. Windows
This formula works fine:
Range("D25").Formula = "=""Corrected = ""&COUNT(5b!A:A)&""" & Chr(10) & "TPP = 8035"""

However, the numeric value at the end "8035" should be a variable rather than hard text, but I just can't get the formula to work in the cell when I try to change it to a variable.

The below doesn't work, and I have tried all sorts of combinations with the quotes, but obviously not the correct one, so any help here would be most appreciated

Dim TotalPP as Integer
TotalPP = 8035

Range("D25").Formula = "=""Corrected = ""&COUNT(5b!A:A)&""" & Chr(10) & "TPP = "" & TotalPP
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about
VBA Code:
Range("D25").Formula = "=""Corrected = ""&COUNT(pcode!c:c)&""" & Chr(10) & "TPP = " & TotalPP & """"
 
Upvote 0
Solution
OMG easy when you know how.
Thank you for this. You wouldn't believe how long I have been trying to figure this one out, and you resolved in seconds.

Thank you again. I can now rest easy.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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