copy what is in the cell where the cursor is without moving the cursor

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
821
Office Version
  1. 365
Platform
  1. Windows
Hi

When I open a wookbook, and then open a spreadsheet, A Private sub worksheet_open macro sets up a title row and drops down to the last A:A cell that has data ( a date) in it. Then it drops one for me to enter a new date.
I then want an event macro to go up one cell (in “A”) and copy that date to Q2
Then when I enter data in “C” another event macro moves the cursor to “I”
Then when I enter data in “I” another event macro moves the cursor to “J”

“A” are dates
Q2 is part of a xlookup formula

This is what I have so far
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
ActiveCell.Offset(-1, 0).Range("A1").Select
' copy what is in the cell to Q2, then
ActiveCell.Offset(1, 0).Range("A1").Select
' this puts the cursor back to the cell that the new date was entered
If Target.Column = 3 Then
ActiveCell.Offset(0, 6).Range("A1").Select
If Target.Column = 6 Then
ActiveCell.Offset(0, 1).Range("A1").Select
End If
End If
End If
End Sub
This event macro works fine from …If target.column=3..
I’m trying to add the ..column=1 part

I don’t know how to copy the previous date to Q2 with out moving to Q2



mike
 
It's also a good ideal to use "With"

Like this:

Excel Formula:
Private Sub CommandButton1_Click()
'Using with
Dim ans As String
ans = ActiveSheet.Name

With Sheets(ans)
.Range("A1").Copy Sheets("Alpha").Range("A1")
.Range("G1").Copy Sheets("Alpha").Range("A2")
End With
End Sub
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
When I open the worksheet, The cursor is now on the first empty cell in A:A, I added a macro to move up one and copy what is there to Q2 and move back down
VBA Code:
Sub copyandpaste()
Range("Q2").Value = ActiveCell.Offset(-1, 0).Value
End Sub

Pro tip: you don't have to .Select cells to copy or paste. The code above copies the value from the cell above the active cell to Q2 without selecting any cells.
 
Upvote 0
There is no script that I know of that will move the cursor.
Now I can have a script that can select a range but that does not move the cursor.

You said: "then I want the cursor to go back to where i put in the new date."
The cursor may be down on the Task bar or any place.

@ My Answer Is This
I could be wrong, but I think what Still Learning meant by "moving the cursor" is just selecting a different cell. I don't think he/she meant actually moving the mouse cursor. I could be wrong though.
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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