activation of macro from worksheet change

EDUCATED MONKEY

Board Regular
Joined
Jul 17, 2011
Messages
218
hello i would like some help with the code below, it works reasonably well but requires me to click the cell that data has just been pasted into, what i would like is that it runs when data is pasted in

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 Dim intersection As Range
    Dim box As Integer 'the row in column K
    Dim postalServiceId As String
    Set intersection = Intersect(Target, Range("K:K"))
    If Not intersection Is Nothing Then
            box = Target.Row
            postalServiceId = Worksheets("extractedData").Cells(box, 11).Value 'get the number
            If (Len(postalServiceId) > 14) Then ' greater the 14 must be hermes
            Worksheets("extractedData").Cells(box, 10).Value = "hermes"
            Cells(box, 3).Interior.Color = RGB(0, 255, 0) 'change the order number to green
            ElseIf (Len(postalServiceId) = 14) Then ' must be royal mail
            Worksheets("extractedData").Cells(box, 10).Value = "royal mail"
            Cells(box, 3).Interior.Color = RGB(0, 255, 0) 'change the order number to green
            End If
   End If
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Not clear what you are trying to do but can you try the worksheet change event instead of SelectionChange
 
Upvote 0
what i would like is that it runs when data is pasted in
Then instead of using the "Worksheet_SelectionChange" event, use the "Worksheet_Change" event, that runs when data is manually updated (i.e. pasting a value into a cell).
You can limit it to only run when cells in a defined range are updated.
By default, it defines "Target" as the range that was just updated, so you can do an Intersect between the Target range and the range you are checking to see in the cells(s) updated fall in your desired range.
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,360
Members
448,888
Latest member
Arle8907

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