ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   help with VB/Macro to shift cells (https://www.excelbanter.com/excel-discussion-misc-queries/86646-help-vbulletin-macro-shift-cells.html)

[email protected]

help with VB/Macro to shift cells
 
Hello -
I have a basic spreadsheet with the following information. Cells
A2:A11 contain basic number valus. Cell A1 is blank.

What I would like to accomplish is for a user to enter a value into
cell A1 and have that information replace the value in A2 and shift the
rest of the values in the column down. I only want to store 10 numbers
(ie A2:A11) at a time.

Can anyone provide me with the knowledge on how to accomplish this?

Thanks!


Bob Phillips

help with VB/Macro to shift cells
 
'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A1"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Range("A2:A10").Copy Range("A3:A11")
Range("A2").Value = Target.Value
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

wrote in message
oups.com...
Hello -
I have a basic spreadsheet with the following information. Cells
A2:A11 contain basic number valus. Cell A1 is blank.

What I would like to accomplish is for a user to enter a value into
cell A1 and have that information replace the value in A2 and shift the
rest of the values in the column down. I only want to store 10 numbers
(ie A2:A11) at a time.

Can anyone provide me with the knowledge on how to accomplish this?

Thanks!




mrice

help with VB/Macro to shift cells
 

Dan

Try the attached.

It's a short macro linked to the worksheet change event.


+-------------------------------------------------------------------+
|Filename: Book1.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4725 |
+-------------------------------------------------------------------+

--
mrice

Research Scientist with many years of spreadsheet development experience
------------------------------------------------------------------------
mrice's Profile: http://www.excelforum.com/member.php...o&userid=10931
View this thread: http://www.excelforum.com/showthread...hreadid=538587


dan

help with VB/Macro to shift cells
 
This is perfect! Thanks so much.



All times are GMT +1. The time now is 09:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com