Worksheet_Change Question

LearnMeExcel

Well-known Member
Joined
Aug 11, 2009
Messages
746
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi
when i use this event
Private Sub Worksheet_Change(ByVal Target As Range)
i want to check the Active cell
for example :
i am in CEll R15
i want to check if the cell P15 = "PP1"
if it is ok take the value which i will entered in Cell R15 and then copy it to Sheets("Truck")
first problem when i enter the value to R15 then press enter the active cell will be R16
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
yes, but TARGET refers to R15, i.e. it is the cell (or range of cells) that you are changing
 
Upvote 0
Code:
[COLOR="Blue"]Private[/COLOR] [COLOR="Blue"]Sub[/COLOR] Worksheet_Change([COLOR="Blue"]ByVal[/COLOR] Target [COLOR="Blue"]As[/COLOR] Range)
    [COLOR="Blue"]If[/COLOR] Range("P15") = Range("PP1") [COLOR="Blue"]Then[/COLOR]
        Target.Copy Sheets("Truck").Range("A1")
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
yes, but TARGET refers to R15, i.e. it is the cell (or range of cells) that you are changing

do you mean to use if target.value Not activeCell.value

sektor
i need to check many cells not just R15
R15
R16
R17
.
.
.
.
 
Upvote 0
target is the range that you are changing. It might consist of one cell or a number of cells

activecell is the single cell that is currently active, which usually changes after you enter something into a sheet

so you can use target.copy in the same way you might consider activecell.copy for example

or you could look at every cell in your range, by using
Code:
dim cl as range
for each cl in target
msgbox cl.value & vbcr & cl.address' for example, or another action
next cl
I often use colour as a way of understanding which ranges are being used in my code
target.interior.colorindex = 6
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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