Cursor as input in a macro
-
QUESTION: In a macro I want to use not only the input of a spreadsheet using the following command result2 = Application.InputBox("place the cursor on the name you want information from", "name?", Type:=8) Because the name is build up in three different columns, first, middle and surname, I need then the cursor to move by using ActiveCell.Offset(0,-1) This is all working fine the first time. However when I want to repeat the command, the cursor stages on the original position, so the offset command returns the wrong information. How can I manage or control the cursor? I looked everywhere and did not find the right command. I appreciate any tips you can give me. Harry ANSWER: Harry, 1. First of all your code should read: Set result2 = Application.InputBox("place the cursor.... If you omit the "Set" you cannot set a Type:=8 which is a range. 2. I think what you need to do is use the row element (first position) from the Offset method. For i = 1 to ActiveSheet.UsedRange.Rows.Count ActiveCell.Offset(i,-1) Next i In this way your code will move through the whole spreadsheet. Kind ---------- FOLLOW-UP ---------- QUESTION: Thnx for the quick respons. However, this code does not put the cursor on the requested cell, so the offset command still starts from the wrong position. I am looking for a command which will put the cursor on the cell I use as input for the Application.inputbox When the cursor moves to that cell, I get the right action from the offset command. Do you have a solution? thnx Harry
-
Answer:
Harry, Your question is not clear to me. Please attach a print screen or mail me a workbook on [email protected] Kind FOLLOW UP: Harry, I received your workbook and program. Attached revised version: Option Explicit Sub Cursormove() 'presentation of the name, to use for selection on another worksheet Dim vnm As String 'First name Dim anm As Range 'Surname Dim znm As String 'to use to search Dim name As String 'for presentation Dim iresult As Integer Dim sTemp As String Dim rep As name Do If iresult = 6 Then Set anm = Application.InputBox("put the cursor on the requested surname", "Name", Type:=8) anm.Select Else If ActiveCell <> "" Then Set anm = ActiveCell End If End If Select Case ActiveCell.Column Case 1 name = Left(anm, 1) & ActiveCell.Offset(0, 1) Case 2 name = Left(ActiveCell.Offset(0, -1), 1) & anm End Select MsgBox name rep: iresult = MsgBox("do you want to select another name?", vbYesNo) 'vbYes = 6 'vbNo = 7 'after respons Yes, you can put the cursor on another cell and the value is put in anm, but the cursor 'stayes on the original cell, with the result that the wrong first letter of the first name. 'MsgBox iresult Loop Until iresult = 7 'I use name to select on another sheet. End Sub
Miningco.com Visit the source
Related Q & A:
- How do I change the cursor from a blinking black block to a blinking line?Best solution by Server Fault
- How do you set just a general macro on your keyboard?Best solution by microsoft.com
- How do you put a TV on input without a remote?Best solution by Yahoo! Answers
- I need some input about a Porshe 928?Best solution by Yahoo! Answers
- How to make my cursor much larger and a bright color too?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.