If And Statement with Variable Range

sushi514

New Member
Joined
Nov 13, 2020
Messages
30
Hi All,

I think I'm having issues with my variable range when I try to use the below. I'm just needing to force a "Yes" value in any cells in Columns D3 - E3 (going down all rows that can vary each time) if they are blank, but only if the corresponding cell in Column F reads "Yes" as well:

If Range("D3:E" & Range("A" & Rows.Count).End(xlUp).Row).Value = "" And Range("F3:F" & Range("A" & Rows.Count).End(xlUp).Row).Value = "Yes" Then
Range("D3:E").Value = "Yes"
End If

Any suggestions?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
How about
VBA Code:
Sub sushi()
   With Range("D3:E" & Range("A" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace("if((@="""")*(" & .Offset(, 2).Resize(, 1).Address & "=""Yes""),""Yes"",@)", "@", .Address))
   End With
End Sub
 
Upvote 0
Thank you! I realized what I needed was the opposite; to fill the blanks in Columns D3 - E with "Yes" only if F was blank, so I changed it to this:

Sub testf2()

With Range("D3:E" & Range("A" & Rows.Count).End(xlUp).Row)
.Value = Evaluate(Replace("if((@="""")*(" & .Offset(, 2).Resize(, 1).Address & "=""""),""Yes"",@)", "@", .Address))
End With
End Sub

But now I keep getting zero values for where Column F reads "Yes"
 

Attachments

  • Example.png
    Example.png
    6.5 KB · Views: 0
Upvote 0
Will columns D & E be blank, or can they have values you want to keep?
 
Upvote 0
For cells in columns D & E that already have values (in this case, "OK"), should remain as-is. Only where F is blank do I want to force "Yes" in Column D, where cells in D are blank. And where F is blank do I want to force "Yes" in Column E, where cells in E are blank. Basically if I were doing this manually, I filter on Column F for blanks, then force "Yes" wherever blank in D and E (expected values highlighted in attached).
 

Attachments

  • Example2.png
    Example2.png
    5.9 KB · Views: 1
Upvote 0
OK, try
VBA Code:
Sub sushi()
   With Range("D3:E" & Range("A" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace("if((@="""")*(" & .Offset(, 2).Resize(, 1).Address & "=""""),""Yes"",if(@="""","""",@))", "@", .Address))
   End With
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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