Use VBA to create a list after scanning data

mbagz

New Member
Joined
Mar 22, 2017
Messages
14
Hi All,

I have been trying to wrap my head around how to write this, but I need help.

Basically, I want to scan a large set of data (mostly dates) and return upcoming data + their respective tasks. The tricky thing is that I don't want to return tasks that are already "done". Below is a sample of my data:

Project NameProject CoordinatorTask #1StatusTask #2Status
Project#1Mark3/14/2017Expected4/20/2017Expected
Project#2James3/25/2017Done3/26/2017Expected
Project#3Jimmy3/24/2017Expected4/14/2017Expected

<tbody>
</tbody>

I want to return the following on a new sheet:
Project NameProject CoordinatorTask NameTask Due DateTask StatusDays until Due Date
Project #1MarkTask #13/14/2017Expected-8
Project #2JamesTask #23/26/2017Expected4
Project #3JimmyTask #13/24/2017Expected2
Project#3JimmyTask #23/28/2017Expected6

<tbody>
</tbody>


For the new list on the new sheet, I need to display any dates past due + any due dates coming up in the next week. Is this possible with VBA? or is there a better way to automatically sort the data and do this?

I appreciate any help, or any direction anyone can provide on this for me.
 
Try this for results on sheet1.
Code:
[COLOR="Navy"]Sub[/COLOR] MG23Mar14
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Ray = Sheets("Data").Range("B1").CurrentRegion
ReDim nray(1 To UBound(Ray, 1) * 10, 1 To 11)
nray(1, 1) = "Project Name": nray(1, 2) = "Project Code": nray(1, 3) = "Manager"
nray(1, 4) = "Project coordinator": nray(1, 5) = "Designer": nray(1, 6) = "Client Rep"
nray(1, 7) = "Project Rep": nray(1, 8) = "Task #n": nray(1, 9) = "Expected date"
nray(1, 10) = "Status of Task #n": nray(1, 11) = "Days until Deadline"
c = 1
[COLOR="Navy"]For[/COLOR] n = 3 To UBound(Ray, 1)
   [COLOR="Navy"]For[/COLOR] Ac = 16 To UBound(Ray, 2)
     [COLOR="Navy"]If[/COLOR] IsDate(Ray(n, Ac)) [COLOR="Navy"]Then[/COLOR]
       [COLOR="Navy"]If[/COLOR] DateDiff("d", Date, Ray(n, Ac)) < 8 And Not UCase(Ray(n, Ac + 1)) = "DONE" [COLOR="Navy"]Then[/COLOR]
         c = c + 1
          nray(c, 1) = Ray(n, 1)
          nray(c, 2) = Ray(n, 19)
          nray(c, 3) = Ray(n, 8)
          nray(c, 4) = Ray(n, 9)
          nray(c, 5) = Ray(n, 10)
          nray(c, 6) = Ray(n, 11)
          nray(c, 7) = Ray(n, 12)
          nray(c, 8) = Ray(1, Ac)
          nray(c, 9) = Ray(n, Ac)
          nray(c, 10) = Ray(n, Ac + 1)
          nray(c, 11) = DateDiff("d", Date, Ray(n, Ac))
       [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]With[/COLOR] Sheets("Sheet1").Range("A1").Resize(c, 11)
    .Value = nray
    .Borders.Weight = 2
    .Columns.AutoFit
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
It says subscript out of range on this line:
If DateDiff("d", Date, Ray(n, Ac)) < 8 And Not UCase(Ray(n, Ac + 1)) = "DONE" Then
 
Upvote 0
Actually, your code works beautifully on the Example file I provided. When I tried to use it on my actual sheet, it didn't work. I think it's because the first column actually starts out at J1, but I changed part of your code to :
Ray = Sheets("Data").Range("J1").CurrentRegion

Any idea why it still isn't working?

EDIT: Actually, I think I understand what is going on. The cells have formulas inside them that pull values from other excel files. Maybe the code isn't reading "DONE", but it is reading the path "C/documents/file/examples.xlsx....." COuld that be it?
 
Last edited:
Upvote 0
Here is something I tend to post when I see a thread progressing the way this particular thread has progressed...

For future questions you may ask, please do not simplify your question for us... doing so will get you a great answer to a question you do not actually have and which you do not actually care about AND it will almost always lead to you coming back for help when the solution we give you for the simplified question cannot be applied to your actual data and its layout. One thing you must keep in mind when you ask a question in a forum... the people you are asking to help you know absolutely nothing about your data, absolutely nothing about how it is laid out in the workbook, absolutely nothing about what you want done with it and absolutely nothing about how whatever it is you want done is to be presented back to you as a result... you must be very specific about describing each of these areas, in detail, and you should not assume that we will be able to "figure it out" on our own. Remember, you are asking us for help... so help us to be able to help you by providing the information we need to do so, even if that information seems "obvious" to you (remember, it is only obvious to you because of your familiarity with your data, its layout and the overall objective for it).
 
Upvote 0
You are correct. It was completely my fault for simplifying the problem.

However, I do want to thank MickG for writing out all the code. I figured out a solution. There were two problems, and both were a result of my over-simplification.
1. The data on the sheet is grabbed from multiple excel sheets, so i'm pretty sure excel reads the file path as a value and not the actual value displayed.
2. Dates of 1/0/1990 were displayed in my sheet. I removed them and this fixed my problem.

Now, my question is, can excel actually ready the displayed value instead of the file path? and is there a way to automatically delete all dates showing 1/0/1990 at the begging of the script? Both of these are specific to my problem, but there has been so much help already so I'm very happy :)
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

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