If, Case, and String Help

Smoakstack

Board Regular
Joined
Mar 28, 2011
Messages
79
I have data coming into a sheet via copy and paste. The thing is, i only want them to copy and paste a certain way. ie: If they sort there data wrong before copying and pasting, then I want a msgbox to come up and tell them they are doing it wrong. Here is the code I have:

Sub Model1()

Select Case Sheet2.Range("D4").Value
Case 1 To 1500

'what happens if it meets criteria

Case Else
Reply = MsgBox("Please sort data by area only.", vbOKOnly, Error)

Application.ScreenUpdating = False
'Unlocks Information
OSTExport20.Unprotect Password:=""
Sheet1.Unprotect Password:=""
Sheet2.Unprotect Password:=""
Sheet3.Unprotect Password:=""
Sheet4.Unprotect Password:=""
Sheet5.Unprotect Password:=""
Sheet6.Unprotect Password:=""
Sheet7.Unprotect Password:=""
Sheet8.Unprotect Password:=""
Sheet9.Unprotect Password:=""
Sheet10.Unprotect Password:=""
Worksheets("On-Center Output").Range("D3:N926").ClearContents
'Locks Information
OSTExport20.Protect Password:=""
Sheet1.Protect Password:=""
Sheet2.Protect Password:=""
Sheet3.Protect Password:=""
Sheet4.Protect Password:=""
Sheet5.Protect Password:=""
Sheet6.Protect Password:=""
Sheet7.Protect Password:=""
Sheet8.Protect Password:=""
Sheet9.Protect Password:=""
Sheet10.Protect Password:=""
Application.ScreenUpdating = True
Exit Sub
End Select
End Sub

It would be checked using a workbook change event. problem is, linking the two together.

Essentially I am checking so that if d4 is not a number from 1-1500, then to pop up a message box saying to sort it by area only. But I come up with errors.

D3 should have text and D4 should have a number between 1 and 1500. Im not sure what I am doing wrong? Any guidance would greatly help
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
forgot other data.

If Target <> "" And Sheet2.Range("X1") = "" And Sheet2.Range("D4") < 1500 And Sheet2.Range("D4") > 0 Then

'do whats needed

Else: Call Model1


End If
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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