View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
tracks via OfficeKB.com tracks via OfficeKB.com is offline
external usenet poster
 
Posts: 23
Default please help with syntax in code

Dave Peterson wrote:
You could almost (but not quite) do something like this:

Option Explicit
Sub test()
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Worksheets("daily crane info").Range("I7,AA15:AF15")
Set rng2 = Worksheets("crane wt summary").Cells(Rows.Count, 1).End(xlUp)
rng1.Copy _
Destination:=rng2.Offset(1, 0)
End Sub

But since rng1 consists of multiple areas (I7 and AA15:AF15), this will fail.

Without knowing exactly what you want, maybe something like this will help:

Option Explicit
Sub test()
Dim RngToCopy As Range
Dim DestCell As Range
Dim myArea As Range
Dim iCtr As Long

With Worksheets("daily crane info")
Set RngToCopy = .Range("I7,AA15:AF15")
End With

With Worksheets("crane wt summary")
Set DestCell = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With

iCtr = 0
For Each myArea In RngToCopy.Areas
myArea.Copy _
Destination:=DestCell.Offset(0, iCtr)
iCtr = iCtr + 1
Next myArea

End Sub

This sample may be more clear:

Option Explicit
Sub test()

Dim DestCell As Range

With Worksheets("crane wt summary")
Set DestCell = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With

With Worksheets("daily crane info")
.Range("I7").Copy _
Destination:=DestCell

.Range("AA15:AF15").Copy _
Destination:=DestCell.Offset(0, 1)
End With

End Sub
HI Dave: I did not follow your first example of code, so I used the second. I got a complier error at destination:= syntax eror , i do not understand looks ok to me . if you have any further suggests iam always here. soory i am so long getting back to you

rick mason
i am testing the following code and get syntax error at copy line
subtest()

[quoted text clipped - 11 lines]
--
Message posted via http://www.officekb.com



--
Message posted via http://www.officekb.com