Thread: Offset
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Offset

did you try

Loop Until IsEmpty(ActiveCell.Offset(0, -1))

as we both suggested.

--
Regards,
Tom Ogilvy



"DavidM" wrote:

Hi JLatham and Tom

Thanks for you replies

I have a Header U1 some Text in U2, below U2 Blank cells.

Header T1, Some Data T2 to T10.

I would like to Goto U1 Then Find and select the last cell in column U that
contains data, Copy that cell, then paste to U3 to U10, to the right of
Column T. Or if was T22, paste to U22


Tom your code works fine, By its self I need to do this to other columns,
and I don't think I could use your code 3 or 4 times in a Marco.


This code works fine pasting to the left of Data, I'm Trying to paste to the
right.

Application.Goto Reference:="R1C21"
Range("U1").End(xlDown).Select

Do
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste


Loop Until IsEmpty(ActiveCell.Offset(0, 1))
Selection.ClearContents
End Sub


Hope I've been clear

Dave





"Tom Ogilvy" wrote in message
...
Activecell.offset(0,-1) is column T

Application.Goto Reference:="R1C21"
Range("U1").End(xlDown).Select
Do
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Loop Until IsEmpty(ActiveCell.Offset(0, -1))
Selection.ClearContents
End Sub

I think I would use something like

Sub AddData()
Dim rng As Range, rng1 As Range
Set rng = Cells(Rows.Count, "T").End(xlUp).Offset(0, 1)
Set rng1 = Cells(Rows.Count, "U").End(xlUp)(2)
If rng1.Row = rng.Row Or rng1.Row = 1 Then Exit Sub
Range(rng, rng1).Value = rng1.Offset(-1, 0)
End Sub

If I understand what you are doing.

--
Regards,
Tom Ogilvy


"DavidM" wrote:

Hi all

I've been trying to get this code to paste to the right of any data in
Column T until it comes to a blank cell, then stops.
I've changed the offset values yet cannot get it right. Help appreciated

Header in row 1
Data in Row 2

Application.Goto Reference:="R1C21"
Range("U1").End(xlDown).Select
Do
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Loop Until IsEmpty(ActiveCell.Offset(0, 1))
Selection.ClearContents
End Sub

Thank in Advance

Dave