Running a portion of code within main code

LadyDisdain

New Member
Joined
Apr 9, 2017
Messages
7
I apologise for the vague title - couldn't think of how to phrase this.

I'm creating a system to send email reminders for equipment that needs calibrating. I have a series of IF statements to check the status and due dates for each piece of equipment, and also look at another sheet that is a log of when emails have been sent.

There is more than one scenario where an email would be triggered:
If equipment is available and due date is less than or equal to today AND the equipment ID is not in the Email Log, then send email.
If equipment is available and due date is less than or equal to today AND the equipment ID exists in the Email Log AND the due date logged doesn't equal the current due date, send email.

I don't want to write out the whole code for the email twice, so I tried calling another module but then I have a problem with "EquipID" etc not showing.

HTML:
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    For lRow = 2 To lLastRow
    
                Avail = Cells(lRow, (CNBH("Available")))
                EquipID = Cells(lRow, (CNBH("Equipment ID")))
                EquipName = Cells(lRow, (CNBH("Equipment Name")))
                CalDue = Cells(lRow, (CNBH("Calibration Next Due")))
                CalRem = Cells(lRow, (CNBH("Calibration Reminder Date")))
                CalFreq = Cells(lRow, (CNBH("Calibration Frequency")))
                Class = Cells(lRow, (CNBH("Classification")))
                CalCont = Cells(lRow, (CNBH("Calibration Contact")))
                CalDet = Cells(lRow, (CNBH("Calibration Details")))
                AccCrit = Cells(lRow, (CNBH("Acceptance Criteria")))
                RemDay = Cells(lRow, (CNBH("Rem Day")))
                
    If Avail = False Or Avail = "" Then
        MsgBox EquipID & " is unavailable"

Any ideas? I'm very new to this whole VBA thing.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi LadyDisdain - I'm not exactly sure, not seeing all the code, but this sounds like a variable that was declared locally, within a certain subroutine, that cannot be passed to another subroutine. You may be able to declare a global variable that can be used between subroutines. Hope this helps get things started.

LINK
 
Upvote 0
Hi LadyDisdain - I'm not exactly sure, not seeing all the code, but this sounds like a variable that was declared locally, within a certain subroutine, that cannot be passed to another subroutine. You may be able to declare a global variable that can be used between subroutines. Hope this helps get things started.

LINK

Thank you, this was exactly the problem! I had done this elsewhere in my project, but for some reason I didn't think it would work for this, I must have done it wrong when I tried it initially. It now works!
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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