Event Procedure to add text dependent on value pasted in cell

bh24524

Active Member
Joined
Dec 11, 2008
Messages
365
Office Version
  1. 365
  2. 2007
Hi, I am looking for an event procedure to add additional text to cells that have numbers. These numbers are pasted from another source into column B of the worksheet. There are 2 groups that this is for and each has headers in column B. They appear like this:

1697040227125.png



So basically what I am looking for is when any value is pasted into column B(amount of names changes on a regular basis just as Info) is 30 or higher, for it to add the text "Sample 1" and if the value is 9 or less to add the text "Sample 2". (There will never be any values between 10 and 29, so no need for any provisions there.) So if I were just now pasting the above screen shot data as an example, I would expect it to look like this:

1697040823463.png


Thank you in advance for the time on this!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range
Set d = Intersect(Range("B:B"), Target)
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
    For Each c In d
        If IsNumeric(c) And c <> "" Then
            Select Case c
                Case Is < 9
                    c = c & " Sample 1"
                Case Is > 29
                    c = c & " Sample 2"
            End Select
        End If
    Next
Application.EnableEvents = True
End Sub
 
Upvote 1
Solution
Ah the code was a little more involved than I would have thought. Thank you Scott for the quick response, this is exactly what I was looking for. :)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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