Allowing entries only in Column B using VBA

Dear Experts:

I would like to expand the below macro with the following requirements:

Requirement No. 1:

The macro should check right at the beginning whether the active cell of the worksheet 'Offer' is in Column B (starting from B2).

If not, a msgbox should say that only entries in Column B are allowed.

And Requirement No. 2

... the macro will only run all the way and copy the named range over, if ...

... in any of the cells in Column B (spanning from B2:B80), the value 03-014-00-01 is entered, If any other value is entered and the macro is activated (by pressing a macro button), a msgbox will say that this number is not a valid no.
( I do not want a worksheet change event, ie. not a Macro like ... Sub Worksheet_Change(ByVal Target As Range)). I got the latter solution already.

I have attached a sample file for your convenience.

Thank you very much in advance for your valuable and professional help.

Regards, Andreas


Sub CopyNamedRangeData()

    Dim wS3 As Worksheet
    Dim rCnt As Long, cCnt As Long
    Application.ScreenUpdating = False
    Set wS3 = Worksheets("Offer")
    Application.Range("Set_OMF_Basic").Copy Destination:=Cells(ActiveCell.Row + 1, 1)
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Open in new window


Only-allow-certain-entries-Column-B.xlsm
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Sub CopyNamedRangeData()

    Dim wS3 As Worksheet
    Dim rCnt As Long, cCnt As Long
    
    Application.ScreenUpdating = False
    Set wS3 = Worksheets("Offer")
    
    If Intersect(ActiveCell, Range("B2:B" & wS3.UsedRange.Rows.Count)) Is Nothing Then
    ' If you just want to allow entry in range B2:B80 then do this instead (and
    ' you should say that in the message)
    'If Intersect(ActiveCell, Range("B2:B80")) Is Nothing Then
        MsgBox "Only entries in Column B are allowed"
        Exit Sub
    End If
    
    If ActiveCell.Value <> "03-014-00-01" Then
        MsgBox "Not a valid number"
           Exit Sub
    End If
    
    Application.Range("Set_OMF_Basic").Copy Destination:=Cells(ActiveCell.Row + 1, 1)
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Great job, this did the trick, thank you very much for your professional help. Regards, Andreas
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.