macros for trigering events on focus loose

nattynids

New Member
Joined
Mar 1, 2011
Messages
11
I want to know, can we write a macro that does some acton when we loses our focus from one cell.
To be precise, i have column A which has some values. Now the moment the focus is shifted from any row of column value A, the value in that row of column A should get cpoied to same row of column B.
is it possible to do so or i have to write a macro that cpies the entire content of column A at once?
 
Replace the earlier code with this:

Code:
Private colA As Range
Private prevA As Boolean
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If prevA = True Then Cells(colA.Row, "B") = colA.Value
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        Set colA = Target
        prevA = True
    Else
        prevA = False
    End If
End Sub

it works absolutely fine.
thanks a lot.
i was able to do the simple ones by just recording.
Now i'll try to understand how macros works.
Thanks again.
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
hi again, can u tell me if i need to do the same thing as earlier but col A is in sheet1 & col B is in sheet2 what changes i need to make.
One more help please tell me if u know some links from where i can start to learn hoe to write macros.
 
Upvote 0
Hey there, all you need to do is add either a Sheet2 or a Sheets("Sheet2")

So:
Code:
If prevA = True Then Cells(colA.Row, "B") = colA.Value

becomes:
Code:
If prevA = True Then Sheets("Sheet2").Cells(colA.Row, "B") = colA.Value

I don't know of any good links but I'm sure someone on the forum would be able to help with that.
 
Last edited:
Upvote 0
Hey there, all you need to do is add either a Sheet2 or a Sheets("Sheet2")

So:
Code:
If prevA = True Then Cells(colA.Row, "B") = colA.Value

becomes:
Code:
If prevA = True Then Sheets("Sheet2").Cells(colA.Row, "B") = colA.Value

I don't know of any good links but I'm sure someone on the forum would be able to help with that.

its starts copying from 4th or 5th line of col B on sheet2. i mean it copies the entire content in correct sequence but row 1 of col A on sheet 1 copies to row 4 of col B on sheet 2 & so on.
 
Upvote 0
its starts copying from 4th or 5th line of col B on sheet2. i mean it copies the entire content in correct sequence but row 1 of col A on sheet 1 copies to row 4 of col B on sheet 2 & so on.


and colA is on sheet 2 and colB is on sheet 3. I changed sheet2 to sheet3 in ur code.
 
Upvote 0
and colA is on sheet 2 and colB is on sheet 3. I changed sheet2 to sheet3 in ur code.

Hint: This may be what's causing the problem.

If what you're looking for is that every time a cell in column A of Sheet1 loses focus, the value of the cell in the corresponding row of column A of Sheet2 is copied to the same row of column A of Sheet3, you will need to make a few more changes.

Try to make these yourself. It will be a learning experience for you.
 
Upvote 0
Hint: This may be what's causing the problem.

If what you're looking for is that every time a cell in column A of Sheet1 loses focus, the value of the cell in the corresponding row of column A of Sheet2 is copied to the same row of column A of Sheet3, you will need to make a few more changes.

Try to make these yourself. It will be a learning experience for you.

what i want is when col A of sheet 2 loses focus, value of that row of col A of sheet 2 should get copied to same row of col B of sheet 3. So i wrote your code in sheet 2. and changed sheet2 to sheet 3 so it copies from col A of shet 2 to col B of sheet 3.
This works fine but the only prolem is the row no. it starts copying from row 1 but it starts copying to row 4.

it should be a little change.
Please let me know.
 
Upvote 0
its working fine now.... thanks.
i have one more task at hand for excel. after completing that, i'll search for some macros tutorial... this is the 1st time i am working with macros.
Thanks a ton for your help.
 
Upvote 0
its working fine now.... thanks.
i have one more task at hand for excel. after completing that, i'll search for some macros tutorial... this is the 1st time i am working with macros.
Thanks a ton for your help.


Glad to be of assistance. Good luck with the macros - am sure you will pick them up very quickly. :)
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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