Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VB-macro - Copy from another workook

I have this code to copy certain values from one sheet to another:

Private Sub worksheet_activate()
Dim rAogB As Range
Set rAogB = Worksheets("Sheet2").Range("aogb")
Dim skrivA As Range
Set skrivA = Range("A1")
Dim j As Integer
j = 1
For i = 1 To rAogB.Height
If rAogB(i, 2) = "a" Then
skrivA(j, 1) = rAogB(i, 1)
skrivA(j, 2) = rAogB(i, 2)
j = j + 1
End If
Next i
End Sub

But now my values are located in another workbook (and not only in another
worksheet). How do I refeer to this workbook?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VB-macro - Copy from another workook

Private Sub worksheet_activate()
Dim rAogB As Range
Dim wb As Workbook

Set wb = Workbooks("wbname.xls")
Set rAogB = wb.Worksheets("Sheet2").Range("aogb")
Dim skrivA As Range
Set skrivA = Range("A1")
Dim j As Integer
j = 1
For i = 1 To rAogB.Height
If rAogB(i, 2) = "a" Then
skrivA(j, 1) = rAogB(i, 1)
skrivA(j, 2) = rAogB(i, 2)
j = j + 1
End If
Next i
End Sub


--
HTH

Bob Phillips

"Johannes B." wrote in message
...
I have this code to copy certain values from one sheet to another:

Private Sub worksheet_activate()
Dim rAogB As Range
Set rAogB = Worksheets("Sheet2").Range("aogb")
Dim skrivA As Range
Set skrivA = Range("A1")
Dim j As Integer
j = 1
For i = 1 To rAogB.Height
If rAogB(i, 2) = "a" Then
skrivA(j, 1) = rAogB(i, 1)
skrivA(j, 2) = rAogB(i, 2)
j = j + 1
End If
Next i
End Sub

But now my values are located in another workbook (and not only in another
worksheet). How do I refeer to this workbook?



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
Copy workbook, don't copy macro CongroGrey Excel Discussion (Misc queries) 1 June 13th 08 04:56 PM
macro copy Pammy Excel Discussion (Misc queries) 1 April 28th 07 03:48 PM
Copy Macro. mcertini Excel Programming 1 September 18th 05 05:59 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM


All times are GMT +1. The time now is 01:13 AM.

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"