Dear all,
Please see attached code. I'm sorry for including some unnecessary variables but for some reason I cannot replicate the error by excluding them.
Line 28 gives a Type Mismatch error. I am perplexed by this as Line 24 (added just as a debugging test) which should do exactly the same does pass without an exception. Why does it work outside the loop but not inside the loop?!
Many thanks in advance![]()
1 Private Sub CommandButton1_Click() 2 Dim numCampaigns As Long 3 Dim rangeCampaigns As Range 4 Set rangeCampaigns = Worksheets(6).Range("A:A") 5 numCampaigns = Application.WorksheetFunction.CountA(rangeCampaigns) 6 7 Dim numOrders As Long 8 Dim rangeOrders As Range 9 Set rangeOrders = Worksheets(1).Range("A:A") 10 numOrders = Application.WorksheetFunction.CountA(rangeOrders) 11 12 Dim orderEDM() As Integer 13 Dim orderCampaign() As String 14 Dim orderBU() As String 15 Dim orderDate() As Double 16 17 ReDim orderEDM(numOrders - 1, 1) As Integer 18 ReDim orderCampaign(numOrders - 1, 1) As String 19 ReDim orderBU(numOrders - 1, 1) As String 20 ReDim orderDate(numOrders - 1, 1) As Double 21 22 Dim i As Long 23 24 orderCampaign(0, 1) = Cells(2, 9) 25 26 For i = 0 To numOrders - 2 27 orderEDM(i, 1) = Cells(i + 2, 15) 28 orderCampaign(i, 1) = Cells(i + 2, 9) 29 orderBU(i, 1) = Cells(i + 2, 14) 30 Next i
Bookmarks