Help to modify 1 line of VBA code IF/Then

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - I have a line of code that will check if the row counts of two sheets is less than or equal to a number. But i need to modify the 2nd part to not check the row count but to check if any value = No in column M, data starts on row 3.

VBA Code:
'check if any current and prior day records exist and stop VBA if condition is met
If WsSP.Range("A" & rows.count).End(xlUp).row <= 3 And WsSP1.Range("A" & rows.count).End(xlUp).row <= 3 Then

'other code like format, formulas etc....

MsgBox ("No Current Day or Prior Day Dates")
Else

'other code like format, formulas etc....

End If
End Sub

So SP1 needs to be amended per the above
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this:

VBA Code:
  Dim n As Long
  n = WorksheetFunction.CountIf(WsSP1.Range("M3", WsSP1.Range("M" & Rows.Count).End(xlUp)), "No")
  'check if any current and prior day records exist and stop VBA if condition is met
  If WsSP.Range("A" & Rows.Count).End(xlUp).Row <= 3 And n = 0 Then
    'other code like format, formulas etc....
    MsgBox ("No Current Day or Prior Day Dates")
  Else
    'other code like format, formulas etc....
  End If
 
Upvote 0
Thanks Dante - I will give this a try. I ended up just creating a formula putting it in another cell and referencing it. But i think both accomplish what I am looking for

VBA Code:
With WsSP1
.Range("M1").Formula = "=IF(COUNTIF($M$3:$M$10000,""NO"")>0,""NO"",""Yes"")"
end with
If WsSP1.Range("M1") = "YES" Then
 
Upvote 0

Forum statistics

Threads
1,214,859
Messages
6,121,963
Members
449,059
Latest member
oculus

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