PC Review


Reply
Thread Tools Rate Thread

Determine which cell was populated

 
 
Jock
Guest
Posts: n/a
 
      5th Oct 2009
When a user types a number into a cell, there are 3 ways to move from that
cell, essentially: <tab>, <enter> or click somewhere with the mouse.
As soon as the cell has lost focus, a user form appears allowing the user to
add other data into text boxes which needs to be copied to the cell to the
right of the one with the number in it.
OFFSET() would work but, as virtually any cell could have focus, this isn't
practical.
I need to identify somehow, which cell the number was entered into (will
always be column D) and copy from User form to cell E on the same row.
There may be gaps in column D which is why I can't use the .End(xlUp)
command as the last entry may not be the one just entered.
All help appreciated.
--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      5th Oct 2009
Try setting a public range variable that's updated during a Worksheet_Change
event and go from there.

HTH,
Barb Reinhardt

"Jock" wrote:

> When a user types a number into a cell, there are 3 ways to move from that
> cell, essentially: <tab>, <enter> or click somewhere with the mouse.
> As soon as the cell has lost focus, a user form appears allowing the user to
> add other data into text boxes which needs to be copied to the cell to the
> right of the one with the number in it.
> OFFSET() would work but, as virtually any cell could have focus, this isn't
> practical.
> I need to identify somehow, which cell the number was entered into (will
> always be column D) and copy from User form to cell E on the same row.
> There may be gaps in column D which is why I can't use the .End(xlUp)
> command as the last entry may not be the one just entered.
> All help appreciated.
> --
> Traa Dy Liooar
>
> Jock

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      5th Oct 2009
What yo ucan do is use application.undo, find the active cell, then put the
data back into the cell using application.redo. It is ugly but it works.

"Jock" wrote:

> When a user types a number into a cell, there are 3 ways to move from that
> cell, essentially: <tab>, <enter> or click somewhere with the mouse.
> As soon as the cell has lost focus, a user form appears allowing the user to
> add other data into text boxes which needs to be copied to the cell to the
> right of the one with the number in it.
> OFFSET() would work but, as virtually any cell could have focus, this isn't
> practical.
> I need to identify somehow, which cell the number was entered into (will
> always be column D) and copy from User form to cell E on the same row.
> There may be gaps in column D which is why I can't use the .End(xlUp)
> command as the last entry may not be the one just entered.
> All help appreciated.
> --
> Traa Dy Liooar
>
> Jock

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Oct 2009
If you tie into the worksheet_Change event, then you can use Target to show you
the range that's been changed.

I'd put this into a General Module (not in the worksheet module, not in the
userform module):

Option Explicit
Public WhichCell As Range


Then this would go in the worksheet module that needs the behavior:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then
Exit Sub 'single cell at a time
End If

If Intersect(Target, Me.Range("D")) Is Nothing Then
Exit Sub 'change not in column D
End If

Set WhichCell = Target
UserForm1.Show
Set WhichCell = Nothing
End Sub

And finally, in the userform module:

Option Explicit
Private Sub UserForm_Initialize()
If WhichCell Is Nothing Then
'not called from the worksheet_Change event
Else
'just to show that it works.
MsgBox WhichCell.Address(external:=True)
End If
End Sub


Jock wrote:
>
> When a user types a number into a cell, there are 3 ways to move from that
> cell, essentially: <tab>, <enter> or click somewhere with the mouse.
> As soon as the cell has lost focus, a user form appears allowing the user to
> add other data into text boxes which needs to be copied to the cell to the
> right of the one with the number in it.
> OFFSET() would work but, as virtually any cell could have focus, this isn't
> practical.
> I need to identify somehow, which cell the number was entered into (will
> always be column D) and copy from User form to cell E on the same row.
> There may be gaps in column D which is why I can't use the .End(xlUp)
> command as the last entry may not be the one just entered.
> All help appreciated.
> --
> Traa Dy Liooar
>
> Jock


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i restrict input in a cell until previous cell populated? FRUSTRATED_WITH_EXCEL Microsoft Excel Misc 1 7th Dec 2009 06:01 PM
First populated cell in row array/ Last populated cell in row arra =?Utf-8?B?U2t5c2Nhbg==?= Microsoft Excel Worksheet Functions 7 29th May 2008 05:20 PM
Determine if Column Populated kirkm Microsoft Excel Programming 4 9th Apr 2008 07:31 AM
formula for a cell which is blank returns populated cell =?Utf-8?B?R3JhY2V5MQ==?= Microsoft Excel Misc 1 2nd Feb 2007 09:17 AM
How to determine when a DataGridView's DataSource is finished being populated johneevo Microsoft ADO .NET 2 5th Apr 2006 06:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.