cannot add value to array

ouvay

Board Regular
Joined
Jun 9, 2022
Messages
131
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I have this code involving adding 3 bits of data to 3 multi dimensional arrays - running some processes and then printing back from one array

Problem I am having is writing the calculated result back to the array

Please have a look and tell me where I am wrong.. I am not posting the entirety of the code to keep things simple and understandable

VBA Code:
Sub indexARray_V2()

TurnOff
On Error Resume Next

Dim Sponsor As Double

Dim a() As Variant                'this is the first array - code looks in here for results 
Dim b() As Variant                'this is the second array - code looks in here for results if not found in first array
Dim data() As Variant           'this is where I get the search data -- first and second array results are also printed here in different columns


lastrow_chart = chart1.Cells(1, 1).End(xlDown).Row
lastrow_chart2 = chart2.Cells(Rows.Count, 1).End(xlUp).Row
lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row

Dim currentMax As Long, startingPoint As Long

startingPoint = 507552
currentMax = lastrow

ReDim a(1 To lastrow_chart, 1 To 24) As Variant
a = chart1.Range("A2:X" & lastrow_chart)

ReDim b(1 To lastrow_chart2, 1 To 24) As Variant
b = chart1.Range("A2:X" & lastrow_chart2)

ReDim data(startingPoint To currentMax, 1 To 12) As Variant
data = ws.Range("A" & startingPoint & ":L" & currentMax)


For i = startingPoint To currentMax
    currentRow = i - startingPoint + 1   
 
    
    Buyer = FirstNumber(data(currentRow, 2))    'Private Function to get back the first string of numbers from the transaction ID (in data array)   
        
    Sponsor = Right(data(currentRow, 2), Len(data(currentRow, 2)) - narrationType)  'Get the last bit of numbers from the string (in data array)
    
          
                data(currentRow, 8) = Sponsor  'At this point I expect the code to write to the same row in the data array to the 8th column; but unfortunately this does not happen - watch window results are Empty
                If Len(Buyer) = 7 Or Len(Buyer) = 11 Then data(currentRow, 7).Value = Buyer  'Buyer value should be printed to the array too .. but it does not.


Here is the watch window result stopped just after I expect the findings to be printed

1661302465653.png







not sure where I'm going wrong... so I'll gladly provide a snippet of the data I'm working with

Book1
ABCDEFGHIJKL
1Date(Unformatted)Transaction IDNarrationDate2(Unformatted)WithdrawalDeposit AmountBuyerSponsorDate 1st Pay/PayOffUniqueRemarks
203/01/22T36000007401I3535079N00322177681180703/01/22242252022/01/03OK
303/01/22T36000007401I3530776N00322177681180403/01/224037.52022/01/03OK
403/01/22T000050497I000046696N00322177681181103/01/2228502022/01/03OK
Sheet1



Basically at this point ... column two should be broken down and the two sets of numbers should be added to the array - after which I will be running further calculations on them.. but I'm having trouble getting that bit down
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi,
This seems like just a small mistake.

VBA Code:
data(currentRow, 7).Value = Buyer

should be as follows, because an array doesn't have a value property.

VBA Code:
data(currentRow, 7) = Buyer
 
Upvote 0
Hi,
This seems like just a small mistake.

VBA Code:
data(currentRow, 7).Value = Buyer

should be as follows, because an array doesn't have a value property.

VBA Code:
data(currentRow, 7) = Buyer
Hi! yeah, thanks for pointing that out.. I typed out the .value in my desperation to look for an solution :)
 
Upvote 0
I've solved the issue... vba is a funny space

Problem seemed to go away when I defined currentRow
VBA Code:
Dim currentRow as Long
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top