Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Copy workbook, don't copy macro | Excel Discussion (Misc queries) | |||
macro copy | Excel Discussion (Misc queries) | |||
Copy Macro. | Excel Programming | |||
how to count/sum by function/macro to get the number of record to do copy/paste in macro | Excel Programming |