View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Andy Andy is offline
external usenet poster
 
Posts: 8
Default Which VBA code is better


"Alan Beban" wrote in message
...
Andy wrote:
I have the following codes and would like to know which one is more
effective and the difference.

Sub Test1()
Dim myRow As Single

Range("A1") = Range("ItemTitle").Offset(myRow)
Range("B1") = Range("QtyTitle").Offset(myRow)

End Sub

Sub Test2()
Dim myRow As Single

Range("A1") = Cells(myRow, Range("ItemTitle").Column)
Range("B1") = Cells(myRow, Range("QtyTitle").Column)

End Sub

I like Test1 more as it is easier to write and seems to me that Test2
may
need a worksheet qualifier if it's referencing another worksheet.

Thanks
Andy, HK


Notwithstanding advice about ALWAYS using worksheet qualifiers, another
tool you might want to consider, if using the code in a General Module, is
the following, which doesn't require such qualification, without regard to
which sheet is active:

Set rngA = Sheets(2).range("A1")
rngA.Value = rngA(myRow, range("ItemTitle").Column)

Alan Beban


Thanks Alan, I'll certainly consider this approach. Learned few things
today, how lucky I am, thank you guys.

Andy