ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, am working an a worksheet where I need to lookup id in an other worksheet.
The script works as long as I am staying on the same row. When pressing key up or enter the corresponmding lookup information is not placed on the very same row.
In short terms, I want the lookup data to be enterd on the same row no matter what key I am pressing.
The script:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cfind As Range
On Error Resume Next
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
thisRow = ActiveCell.Row
With Worksheets("Blad2")
.With Columns("h:h")
Set cfind = .Cells.Find(What:="CBSC01CA" & Target.Value, LookAt:=xlWhole)
Am I right in thinking this is what your programme does (sorry, I haven't done much macro-writing, and it's all been with OpenOffice rather than Excel):
Code:
* Given variable "Target" which will be a cell in column "A"
* Search for a cell in worksheet 2, column H whose value is "CBSC01CA" followed by
the contents of cell A
* If you've found a cell which matches the above criteria, then copy cells D and I
in the row of the cell into the cells B and C in the row of the highlighted
cell.
Is this right? And the problem is that when you enter text, depending on how you finish editing the text (pressing enter/escape/an arrow key) the position of the highlighted cell is different when you call the function?
In this case, how does the sub get called? Is this done by another one of your subs?
At the moment I am not calling any subs, but as it seems this is the way to do it. I am fiddeling now with subs which act on keypress. When arrow down or return is pressed => thisRow -1, if arrow up key is pressed => thisRow +1 etc ...
The challange now is that triggering the sub functions should only occur when entering the IDs in column. Plus that the subs trigger can only be called from within with the above function ( meaning editing other cells should trigger nothing )
I will do some trail & error. In case I am successful, I will post this later.
In case someone knows a link for more detailed info on how to do this, I will be very happy.
If you aren't calling the sub, how does it get run?
And your approach is a good one - if you capture the keyboard input, then you can work out which row it was originally in and check it's in column A, then pass these values to the sub you posted in your first post (obviously, removing the corrections you had in it for pressing ENTER). This way, you have only one sub which does the actual heavy-lifting (copying the data over), and you can correct the cursor moving about the spreadsheet.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.