Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Relative Reference help

I am trying to create a macro that will take values that change and
paste them one line below where the previous days numbers where
pasted. So if A1 is a ten I need it to paste in A2. Then the next
day A1 may be a 15 and I need it to paste in A3. I have tried many
things and it always copies the cell above instead of A1. Thanks in
advance.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Relative Reference help

Hi,

Try this, it pastes any value entered in A1 into the empty cell at the
bottom of the data list in column A.

Private Sub Worksheet_Change(ByVal Target As Range)
lastrowcola = Range("A65536").End(xlUp).Row
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
Range("A1").Select
Selection.Copy
Cells(lastrowcola + 1, 1).Select
ActiveSheet.Paste
End If
End Sub

Mikw

"Barnej75" wrote:

I am trying to create a macro that will take values that change and
paste them one line below where the previous days numbers where
pasted. So if A1 is a ten I need it to paste in A2. Then the next
day A1 may be a 15 and I need it to paste in A3. I have tried many
things and it always copies the cell above instead of A1. Thanks in
advance.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Relative Reference help

Mike,
I was trying to solve this for OP and was using change event code
with Line 2 = Application.Undo ' thinking whatever was entered last(before)
had not yet been copied down to the Bottom. If that were the case, could you
kindly show how this would be acheived?
TIA,
Jim

"Mike H" wrote:

Hi,

Try this, it pastes any value entered in A1 into the empty cell at the
bottom of the data list in column A.

Private Sub Worksheet_Change(ByVal Target As Range)
lastrowcola = Range("A65536").End(xlUp).Row
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
Range("A1").Select
Selection.Copy
Cells(lastrowcola + 1, 1).Select
ActiveSheet.Paste
End If
End Sub

Mikw

"Barnej75" wrote:

I am trying to create a macro that will take values that change and
paste them one line below where the previous days numbers where
pasted. So if A1 is a ten I need it to paste in A2. Then the next
day A1 may be a 15 and I need it to paste in A3. I have tried many
things and it always copies the cell above instead of A1. Thanks in
advance.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Relative Reference help

You'd use Application.Undo if you wanted to retrieve the value that was in A1.
But it sounds like you want to use A1 as an input cell and then just move things
to the bottom of that column.

If that's the case, you could use:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim DestCell As Range
Dim NewVal As Variant

With Target
If .Cells.Count 1 Then Exit Sub
If .Value = "" Then Exit Sub
If Intersect(.Cells, Me.Range("a1")) Is Nothing Then
Exit Sub
End If

On Error GoTo ErrHandler:

NewVal = .Range("a1").Value
Set DestCell _
= .Parent.Cells(.Parent.Rows.Count, "A").End(xlUp).Offset(1, 0)

Application.EnableEvents = False
DestCell.Value = NewVal

'clear for next time???
.Value = ""

End With

ErrHandler:
Application.EnableEvents = True

End Sub

If you really wanted to keep that existing value, you could use:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim DestCell As Range
Dim NewVal As Variant

With Target
If .Cells.Count 1 Then Exit Sub
If .Value = "" Then Exit Sub
If Intersect(.Cells, Me.Range("a1")) Is Nothing Then
Exit Sub
End If

On Error GoTo ErrHandler:

NewVal = .Range("a1").Value
Set DestCell _
= .Parent.Cells(.Parent.Rows.Count, "A").End(xlUp).Offset(1, 0)

With Application
.EnableEvents = False
.Undo
End With

DestCell.Value = NewVal

End With

ErrHandler:
Application.EnableEvents = True

End Sub

JMay wrote:

Mike,
I was trying to solve this for OP and was using change event code
with Line 2 = Application.Undo ' thinking whatever was entered last(before)
had not yet been copied down to the Bottom. If that were the case, could you
kindly show how this would be acheived?
TIA,
Jim

"Mike H" wrote:

Hi,

Try this, it pastes any value entered in A1 into the empty cell at the
bottom of the data list in column A.

Private Sub Worksheet_Change(ByVal Target As Range)
lastrowcola = Range("A65536").End(xlUp).Row
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
Range("A1").Select
Selection.Copy
Cells(lastrowcola + 1, 1).Select
ActiveSheet.Paste
End If
End Sub

Mikw

"Barnej75" wrote:

I am trying to create a macro that will take values that change and
paste them one line below where the previous days numbers where
pasted. So if A1 is a ten I need it to paste in A2. Then the next
day A1 may be a 15 and I need it to paste in A3. I have tried many
things and it always copies the cell above instead of A1. Thanks in
advance.



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Relative Reference help

Thank you for all your help. I ended up using it like this


Sub Macro1()
lastrowcola = Range("A65536").End(xlUp).Row
Range("A1:C1").Select
Selection.Copy
Cells(lastrowcola + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

It seems to be doing what I need it to. If you see anything wrong
with how I am doing it please let me know.

Thanks
Jason


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using an offset formula for the reference in a relative reference Cuda Excel Worksheet Functions 6 November 15th 06 05:12 PM
relative reference Swannybuck Excel Discussion (Misc queries) 1 July 26th 06 09:28 PM
Relative reference Lakebum Excel Worksheet Functions 2 December 28th 04 05:57 PM
Relative Reference Barry Givens via OfficeKB.com Excel Discussion (Misc queries) 3 December 17th 04 07:31 PM
relative reference Charlie New Users to Excel 3 December 3rd 04 07:22 PM


All times are GMT +1. The time now is 10:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"