Need help with macro

Mrjcharlton

New Member
Joined
Aug 3, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello!

I am trying to use the below macro to flag an error message when a date range exceeds 7 days.

I have used the below which only applies to the first cell in the column. What must I do to apply it to the whole column, I have 350 rows.

Just to let you know column K is a calculation of days based on dates added to columns H & I.

Also, cell K492 has the value "7" in it.

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("K2").Value > Range("K492").Value Then
MsgBox "Payroll Period can not be more than 7 days"
End If

End Sub





Thank you
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the forum,

Do you really want to have multiple msgbox or would could you work with either a message in another cell or conditional formatting which would simply be easier.
 
Upvote 0
Thank you Trevor!

Ideally I just want something to pop up and alert the end user when they are doing something wrong. I.e adding a date range that exceeds 7 days

I have already added conditional formatting to flag as red if greater than 7. However, this has gone unnoticed in the past, which is very annoying.

Any suggestions would be greatly appreciated

Thanks
 
Upvote 0
Would a userform with a listbox showing either the rows that must be checked or something else as an identifier?
 
Upvote 0
Given the amount of data the end user needs to add, I think that would add a lot of extra work
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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