Consulting

Results 1 to 3 of 3

Thread: I need some help printing an array from a set of values on a worksheet.

  1. #1
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    4
    Location

    I need some help printing an array from a set of values on a worksheet.

    Hi,

    I have this code that I need to complete, and I am having some trouble understanding how arrays work. I need my two arrays to be populated with the values from two columns on a worksheet, but I can't figure out to properly populate the arrays. Thanks in advance for any help.

    Sub HighSpenderList()
    'Declare variables
    Dim i As Integer
    Dim arrNames() As Long
    Dim arrSpent() As Currency
    Dim NumberofRows As Integer
    'Clear out existing records in columns D and E.
    'Start in D4 and E4.
    Range("E4", Columns("E").SpecialCells(xlCellTypeLastCell)).Delete
    Range("D4", Columns("E").SpecialCells(xlCellTypeLastCell)).Delete
    'POPULATE THE ARRAYS 
    NumberofRows = Cells(65536, 1).End(xlUp).Row
    'Set up a For loop ranging from i = 1 to the number of customers.
    For i = 1 To NumberofRows
       If arrNames(i) = Range("A3:AA").Offset(i, 1).Value > 499 Then
            ReDim Preserve arrNames(1 To i)
            i = i + 1
       End If
    Next i
    'With cell A3 as your point of reference, check whether
    'the value of .Offset(i, 1) is at least 500.  If it is,
    'then ReDim Preserve your two arrays to add another element to each,
    'and also write the ith customer name to the end of the
    'names array and the ith amount spent to the end of the
    'amount spent array.
    'NOTE: the ith customer name won't necessarily be the
    'ith element in your array.  For re-dimensioning and keeping
    'track of what array element you are on, it
    'will be helpful to set some integer variable that you manually
    'increment every time you find a high spender.
    End Sub
    Last edited by Aussiebear; 12-11-2015 at 06:03 PM. Reason: applied hash tag to code

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    You may already have an answer at http://www.mrexcel.com/forum/excel-q...worksheet.html

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Please do not cross post across multiple forums. The VBA community doesn't represent that big of a percentage of the world's population and we often are members of multiple forums. People who cross post issues without following forum rules soon become regarded as persons to ignore, and I'm hopeful here that you don't want to go down that track.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •