Results 1 to 1 of 1

Automated Number Allocation & Email individuals

Threaded View

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    Christchurch, NZ
    MS-Off Ver
    Excel 2003
    Posts
    23

    Automated Number Allocation & Email individuals

    Hi all,
    I am trying desperately to get this spreadsheet to conform, my VBA knowledge is limited, and I have tried recording macros etc, but cannot seem to get this to work.
    I have attached the spreadsheet to help out with my explanation.
    In Sheet "CP", the allocate button has the following code attached, but I need it to allocate the numbers based on the volume in F5 for block 1, and F6 for block 2 and so on for each individual based on their values.

    Here is the code I have so far. I have tried to get the button to check first that the remaining amount of numbers in J4 & K4 and if below 0 a message box appears canceling the request and requesting the person to go back and check their allocation figures.

    Private Sub CommandButton2_Click()
    
    Dim CPsh As Worksheet, NAsh As Worksheet
    Dim blocks() As Range, trainers, blockaddress
    Dim i As Long, j As Long, to_allocate As Long, allocated As Long, counter As Long, where As Long
    Randomize
    Set CPsh = Sheets("CP")
    Set NAsh = Sheets("Number Allocation")
    trainers = WorksheetFunction.Transpose(CPsh.Range("A4:A50").Value)
    blockaddress = Split("N3:N1002,N1004:N2900", ",")
    For i = 1 To 2 'to number of blocks
      ReDim Preserve blocks(1 To i)
      Set blocks(i) = NAsh.Range(blockaddress(i - 1))
      blocks(i).ClearContents
      For j = 1 To 40 'all trainers
        counter = 0
        to_allocate = F6 'of course calculate based on data from CPsh and already assigned
        allocated = 0
        Do
          where = 1 + Int(blocks(i).Rows.Count * Rnd)
          If blocks(i).Cells(where) = "" Then
            blocks(i).Cells(where) = trainers(j)
            allocated = allocated + 1
          End If
        Loop Until allocated = to_allocate Or counter > 1000
        If counter > 1000 Then
          MsgBox "Sorry, SparkCRM Auto Allocation has incurred an error. Please press the clear button in Number Allocation and reset."
        End If
      Next j
    Next i
    Me.Hide
    MsgBox ("SparkCRM - Thanks! You have successfully allocated the required number of numbers to the trainers!")
    End Sub
    Once it has done this, I am wanting to filter the information on the 'Number Allocation' sheet and email the respective individuals their allocated numbers. I have looked into filtering the data one by one into another sheet and emailing, but this seems a long rounded way to go about it?

    Any help would be greatly appreciated.
    I have already lost the sheet once due to a '400' error!

    Thanks in advance, Dan
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Email merge unique messages to groups and individuals
    By RagingWahoo in forum Excel General
    Replies: 3
    Last Post: 10-12-2012, 01:15 PM
  2. Automated email coding
    By netgame27 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2010, 02:29 PM
  3. Excel automated email
    By netgame27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2010, 02:29 PM
  4. Copy & Pasting Email addresses into individuals cells
    By patrickchaperon in forum Excel General
    Replies: 4
    Last Post: 02-27-2008, 03:51 AM
  5. Automated email
    By Vlad999 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2008, 07:52 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1