macro "IF" check

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
Just picking up this piece of coding after leaving it for 4 months....I want to remind myself so I correctly modify it....

The coding works as it should, but here is what it should be doing:
It checks if the previous sheet is called "Noon#" (meaning Noon or Noon2, Noon 3, etc) then adds N14 from each sheet named "Noon#". It then adds this sum with R21 and creates this as a time (in decimal form- so increments of 6).

How I would like to tweak- I want to finish the IF basically, so if the the previous sheet is not a "Noon" sheet of some sort, it will JUST make the cell equal to R21 (basically just won't add the previous sheets since they don't exist). thanks for the help!

Code:
WS_Count = ActiveWorkbook.Worksheets.Count    Eqat3 = "="
    nooncnt = 0
        For i = 1 To WS_Count
             Tname = ActiveWorkbook.Worksheets(i).Name
            If Left(Tname, 4) = "Noon" Then
             Eqat3 = Eqat3 & "+" & Tname & "!N14"
             nooncnt = nooncnt + 1
            End If
        Next i
        If nooncnt > 0 Then
        Range("N12").Formula = Eqat3 & "+R21"
    End If
    If IsNumeric(Range("D8").Value) Then
        If Range("R21").Value > (Range("D8").Value + (Range("F8").Value / 60)) Then
            Range("N10").Value = "Error"
        End If
    End If
    Range("N29").FormulaR1C1 = "=R[-17]C"
    Range("N46").FormulaR1C1 = "=R[-17]C"
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Maybe...
Code:
If nooncnt > 0 Then
        Range("N12").Formula = Eqat3 & "+R21"
 Else
 Range("N12").Value =  Range("R21").Value 
End If
HTH. Dave
 
Upvote 0
this looks good! i appreciate it. I ended up writing this:
Code:
   If LCase(ActiveSheet.Previous.Name) Like "noon*" Then        Range("D9") = sFrm5
        Range("F9") = sFrm7
    Else:
        Range("D9") = sFrm6
        Range("F9") = sFrm8
    End If
where the sFrm's are equations
 
Upvote 0

Forum statistics

Threads
1,216,071
Messages
6,128,626
Members
449,460
Latest member
jgharbawi

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