How post define formulas only if cells have a value

Blockhead15

New Member
Joined
Jun 13, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Right now, my code (shown below) applies a formula to column D for all rows. Is there a way to only show the formula if column c <> blank?


ABCDEFG
X99X_Females
X99X_Males
Section 1
Check
01-Jan-2014
01-Jan-2014
01-Jan-2014
APart A
1Part A(657,905,844)(126,690,984)(531,214,860)
2Part B722,544,257139,138,212583,406,045
3SubtotalCheck64,638,41364,638,41364,638,413
BPart B
1Part GCheck64,638,41364,638,41364,638,413
2Part H000
3Part I000
4SubTotalCheck64,638,41364,638,41364,638,413



Formula = "=if(sum(F8:xx8)<>E8,""Check"","""")"
Set Rng = Range("d8:xx" & lastr)
Rng.Cells(1, 3).Formula = Formula
Rng.Cells(1, 3).Copy

For i = 1 To lastr - 6
Rng.Cells(i, 1 + 1).PasteSpecial Paste:=xlPasteFormulas
Next i
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Put this as the line below the For statement:
VBA Code:
If Not Isblank(Cells(i,3)) Then

And this before the Next statement;
VBA Code:
End if
 
Upvote 0
Solution
Also, NEVER used reserved words like "Formula" as the name of variables (or procedures or functions). That cause errors and/or unexpected results, as Excel may not guess correctly which one you are referring to, especially in a statement like this!
Rich (BB code):
Rng.Cells(1, 3).Formula = Formula
 
Upvote 0
Thanks @portews . For the VBA, I need to use IsEmpty but it worked the same way. @Joe4 - appreciate the comments. Cleaned up in my final version.
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,931
Members
449,195
Latest member
Stevenciu

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