View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave O Dave O is offline
external usenet poster
 
Posts: 427
Default Import data from another Worksheet

Here's one way: I've added some lines of code to your routine, and
marked them with '* * * * * to distinguish them.

Sub Retrieve_Info()
dim LastRow as Long '* * * * * added line: declare a variable
P = "C:\Documents and Settings\David Truong\Desktop"
f = "Book2.xlsm"
s = "Sheet1"

'* * * * * long added line he the underscores tell the compiler to
concatenate these three rows.
LastRow = Mid(ActiveSheet.UsedRange.Address, _
InStr(InStr(1, ActiveSheet.UsedRange.Address, ":$") + 2, _
ActiveSheet.UsedRange.Address, "$") + 1,
Len(ActiveSheet.UsedRange.Address))

Application.ScreenUpdating = False
For r = 1 To LastRow '* * * * * this line changed

Everything else stays the same. Note: because the typed lines in this
post may be wrapped by your screen display, the long line above that
calculates LastRow may be wrapped in the wrong place, and generate a
compile error. If that happens, edit those lines of code so the first
line of code starts with LastRow = and ends with an underscore; the
second line should start with InStr( and end with an underscore; the
third line should start with ActiveSheet and end with Address))

Let us know how it goes!
DaveO