TheMadTree
New Member
- Joined
- Mar 23, 2015
- Messages
- 25
Good afternoon guys,
I am working with a nested for each loop to insert data from one workbook to another.
It seems that it's stuck to the first value in the non-continuous range. In the Pineapple workbook range A14 is Banana and range A21 is Apple and it never skips to apple.
Can someone please help me :S
This is my code:
Sub Banana()
Dim Weeknumber As Long
Dim ws As Worksheet
Dim xlrange As Range
Dim xlrange2 As Range
Dim xlrange3 As Range
Dim xlcell2 As Range
Dim xlcell3 As Range
Dim Salesorg As Integer
Dim Score As Variant
Set xlrange2 = Workbooks("Pineapple.xlsm").Sheets("Overview").Range("A14,A21")
For Each xlcell2 In xlrange2
Score = xlcell2.Offset(0, 1).Value
If xlrange2 = "Banana" _
Then Set xlrange3 = Workbooks("Orange.xlsm").Sheets("Pear").Range("A4:A56")
If xlrange2 = "Apple" _
Then Set xlrange3 = Workbooks("Orange.xlsm").Sheets("Salad").Range("A4:A56")
For Each xlcell3 In xlrange3
If xlcell3.Value = Weeknumber Then
xlcell3.Offset(0, 7).Value = Score
End If
Next xlcell3
Next xlcell2
Thank you!
I am working with a nested for each loop to insert data from one workbook to another.
It seems that it's stuck to the first value in the non-continuous range. In the Pineapple workbook range A14 is Banana and range A21 is Apple and it never skips to apple.
Can someone please help me :S
This is my code:
Sub Banana()
Dim Weeknumber As Long
Dim ws As Worksheet
Dim xlrange As Range
Dim xlrange2 As Range
Dim xlrange3 As Range
Dim xlcell2 As Range
Dim xlcell3 As Range
Dim Salesorg As Integer
Dim Score As Variant
Set xlrange2 = Workbooks("Pineapple.xlsm").Sheets("Overview").Range("A14,A21")
For Each xlcell2 In xlrange2
Score = xlcell2.Offset(0, 1).Value
If xlrange2 = "Banana" _
Then Set xlrange3 = Workbooks("Orange.xlsm").Sheets("Pear").Range("A4:A56")
If xlrange2 = "Apple" _
Then Set xlrange3 = Workbooks("Orange.xlsm").Sheets("Salad").Range("A4:A56")
For Each xlcell3 In xlrange3
If xlcell3.Value = Weeknumber Then
xlcell3.Offset(0, 7).Value = Score
End If
Next xlcell3
Next xlcell2
Thank you!