Divide and Conquer

clarka9

New Member
Joined
Mar 21, 2013
Messages
28
I am trying to automate a sheet that will be updated continously as I move on, but I will need the code to break the ranges out for each on the next sheet.
Thanks ALOT!!!!!!!......

First Name</SPAN>Last</SPAN>Assign Begin Dt</SPAN>Assign Retn Dt</SPAN>
Anthony</SPAN>Teft</SPAN>1/7/2013</SPAN>5/31/2013</SPAN>
John</SPAN>Mahoney</SPAN>12/31/2014</SPAN>
Adam</SPAN>Sweet</SPAN>10/13/2008</SPAN>12/31/2013</SPAN>
Gregory</SPAN>Klock</SPAN>3/11/2013</SPAN>3/20/2013</SPAN>
Kevin</SPAN>Sauve</SPAN>3/11/2013</SPAN>3/24/2013</SPAN>
Paul</SPAN>Barnes</SPAN>12/3/2012</SPAN>12/23/2012</SPAN>
Matthew</SPAN>Seibert</SPAN>3/11/2013</SPAN>3/24/2013</SPAN>

<TBODY>
</TBODY>
 
clarka9,

In order to resolve the error message I will have to see your actual workbook.

You can upload your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.


If you can not provide your workbook, then:

Click on the Reply to Thread button, and just put the word BUMP in the post. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
clarka9,

Thanks for the latest workbook.

You did not explain what did not work.

Sample raw data in worksheet Data:


Excel 2007
ABCDE
1First NameLastAssign Begin DtAssign Retn DtLevel
2BobJohnson1/7/20135/31/20135
3JamesWilliam10/13/200812/31/20132
4Tony Black3/11/20133/20/20134
5OtisParker3/11/20133/24/20134
6RobertWilson12/3/201212/23/20124
7KatBrook3/11/20133/24/20134
8JerrySmith12/10/20126/6/20134
9DanWinkle3/4/20133/31/20132
10BethOwens1/7/20133/24/20132
11JakeBlue2/11/20133/15/20142
12
Data


Should I be using the Level's that are in worksheet Data, column E, and copy that number into worksheet Results column D?

1. For James William, should the Results worksheet look like this?


Excel 2007
ABCD
1First NameLastDateLevel
2BobJohnson1/7/20135
3BobJohnson2/7/20135
4BobJohnson3/7/20135
5BobJohnson4/7/20135
6BobJohnson5/31/20135
7JamesWilliam10/13/200863
8JamesWilliam11/13/200863
9JamesWilliam12/13/200863
10JamesWilliam1/13/200963
11JamesWilliam2/13/200963
12JamesWilliam3/13/200963
13JamesWilliam4/13/200963
14JamesWilliam5/13/200963
15JamesWilliam6/13/200963
16JamesWilliam7/13/200963
17JamesWilliam8/13/200963
18JamesWilliam9/13/200963
19JamesWilliam10/13/200963
20JamesWilliam11/13/200963
21JamesWilliam12/13/200963
Results


2. Or, like this?


Excel 2007
ABCD
1First NameLastDateLevel
2BobJohnson1/7/20135
3BobJohnson2/7/20135
4BobJohnson3/7/20135
5BobJohnson4/7/20135
6BobJohnson5/31/20135
7JamesWilliam10/13/20082
8JamesWilliam11/13/20082
9JamesWilliam12/13/20082
10JamesWilliam1/13/20092
11JamesWilliam2/13/20092
12JamesWilliam3/13/20092
13JamesWilliam4/13/20092
14JamesWilliam5/13/20092
15JamesWilliam6/13/20092
16JamesWilliam7/13/20092
17JamesWilliam8/13/20092
18JamesWilliam9/13/20092
19JamesWilliam10/13/20092
20JamesWilliam11/13/20092
21JamesWilliam12/13/20092
Results


What is correct?
1.
or 2.
 
Upvote 0
clarka9,

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub clarka9_V2()
' hiker95, 03/25/2013
' http://www.mrexcel.com/forum/excel-questions/692848-divide-conquer-2.html
Dim wD As Worksheet, wR As Worksheet
Dim r As Long, lr As Long, sr As Long, er As Long, nr As Long
Dim lrra As Long, lrrd As Long, n As Long
Dim m As Long, sm As Long, em As Long
Dim y As Long, sy As Long, ey As Long
Application.ScreenUpdating = False
Set wD = Worksheets("Data")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=wD).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
With wR.Cells(1, 1).Resize(, 4)
  .Value = [{"First Name","Last","Date","Level"}]
  .Font.Bold = True
End With
lr = wD.Cells(Rows.Count, 1).End(xlUp).Row
For r = 2 To lr Step 1
  If wD.Cells(r, 3) = "" Or wD.Cells(r, 4) = "" Then
    nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
    If wD.Cells(r, 3) = "" Then
      wR.Cells(nr, 3) = wD.Cells(r, 4)
      wR.Cells(nr, 4) = wD.Cells(r, 5)
    ElseIf wD.Cells(r, 4) = "" Then
      wR.Cells(nr, 3) = wD.Cells(r, 3)
      wR.Cells(nr, 4) = wD.Cells(r, 5)
    End If
  ElseIf Year(wD.Cells(r, 3)) = Year(wD.Cells(r, 4)) And Month(wD.Cells(r, 3)) = Month(wD.Cells(r, 4)) Then
    nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    wR.Cells(nr, 1).Resize(2, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
    wR.Cells(nr, 3) = wD.Cells(r, 3)
    wR.Cells(nr, 4).Resize(2).Value = wD.Cells(r, 5).Value
    wR.Cells(nr + 1, 3) = wD.Cells(r, 4)
  ElseIf Year(wD.Cells(r, 3)) = Year(wD.Cells(r, 4)) And Month(wD.Cells(r, 3)) <> Month(wD.Cells(r, 4)) Then
    nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    m = Month(wD.Cells(r, 4)) - Month(wD.Cells(r, 3))
    wR.Cells(nr, 1).Resize(m + 1, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
    wR.Cells(nr, 3) = wD.Cells(r, 3)
    wR.Cells(nr, 4).Value = wD.Cells(r, 5)
    With wR.Cells(nr + 1, 3).Resize(m - 1)
      .FormulaR1C1 = "=MONTH(R[-1]C)+1&""/""&DAY(R[-1]C)&""/""&YEAR(R[-1]C)"
      .Value = .Value
    End With
    wR.Cells(nr + m, 3) = wD.Cells(r, 4)
    wR.Cells(nr, 4).Resize(m + 1).Value = wD.Cells(r, 5)
  ElseIf Year(wD.Cells(r, 3)) <> Year(wD.Cells(r, 4)) Then
    sm = Month(wD.Cells(r, 3))
    sy = Year(wD.Cells(r, 3))
    em = Month(wD.Cells(r, 4))
    ey = Year(wD.Cells(r, 4))
    For y = sy To ey Step 1
      If y = sy Then
        nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
        wR.Cells(nr, 1).Resize(, 3).Value = wD.Cells(r, 1).Resize(, 3).Value
        For m = sm + 1 To 12 Step 1
          nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
          wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
          With wR.Cells(nr, 3)
            .FormulaR1C1 = "=MONTH(R[-1]C)+1&""/""&DAY(R[-1]C)&""/""&YEAR(R[-1]C)"
            .Value = .Value
          End With
        Next m
      ElseIf y > sr And y < ey Then
        nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
        wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
        With wR.Cells(nr, 3)
          .FormulaR1C1 = "=MONTH(1)&""/""&DAY(R[-1]C)&""/""&YEAR(R[-1]C)+1"
          .Value = .Value
        End With
        For m = 2 To 12 Step 1
          nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
          wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
          With wR.Cells(nr, 3)
            .FormulaR1C1 = "=MONTH(R[-1]C)+1&""/""&DAY(R[-1]C)&""/""&YEAR(R[-1]C)"
            .Value = .Value
          End With
        Next m
      ElseIf y = ey Then
        nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
        wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
        With wR.Cells(nr, 3)
          .FormulaR1C1 = "=MONTH(1)&""/""&DAY(R[-1]C)&""/""&YEAR(R[-1]C)+1"
          .Value = .Value
        End With
        For m = 2 To em - 1 Step 1
          nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
          wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
          With wR.Cells(nr, 3)
            .FormulaR1C1 = "=MONTH(R[-1]C)+1&""/""&DAY(R[-1]C)&""/""&YEAR(R[-1]C)"
            .Value = .Value
          End With
        Next m
        nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
        wR.Cells(nr, 1).Resize(, 2).Value = wD.Cells(r, 1).Resize(, 2).Value
        wR.Cells(nr, 3).Value = wD.Cells(r, 4).Value
      End If
    Next y
    lrra = wR.Cells(Rows.Count, 1).End(xlUp).Row
    lrrd = wR.Cells(Rows.Count, 4).End(xlUp).Row
    wR.Range("D" & lrrd + 1 & ":D" & lrra) = wD.Cells(r, 5)
  End If
Next r
lr = wR.Cells(Rows.Count, 1).End(xlUp).Row
wR.Range("C2:C" & lr).NumberFormat = "m/d/yyyy"
wR.Cells.EntireColumn.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the clarka9_V2 macro.
 
Upvote 0
clarka9,

I do not have a clue to what you are doing, or requesting.

In the last attached workbook, the raw data in worksheet Data, does not match the data in worksheet Results:


Excel 2007
ABCDE
1First NameLastAssign Begin DtAssign Retn DtLevel
2BobJohnson1/7/20135/31/20135
3BobJohnson10/13/200812/31/20132
4BobJohnson3/11/20133/20/20134
5BobJohnson3/11/20133/24/20134
6BobJohnson12/3/201212/23/20124
7BobJohnson3/11/20133/24/20134
8BobJohnson12/10/20126/6/20134
9BobJohnson3/4/20133/31/20132
10BobJohnson1/7/20133/24/20132
11BobJohnson2/11/20133/15/20142
Data



Excel 2007
ABCD
1First NameLastDateLevel
2AnthonyTeft412815
3AnthonyTeft2/7/20135
4AnthonyTeft3/7/20135
5AnthonyTeft4/7/20135
6AnthonyTeft414255
7AdamSweet10/13/20082
8AdamSweet11/13/20082
9AdamSweet12/13/20082
10AdamSweet1/13/20092
11AdamSweet2/13/20092
Results



We have a communication problem.

Click on the Reply to Thread button, and just put the word BUMP in the post. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0
If you run the Macro, it doesnt complete the entire data entries on the Result tab.
A debug appears in the formula. Try to run it yourself.
 
Upvote 0
clarka9,

OK. I did check your last workbook again.

Everything keeps changing.

Your new worksheet Data contains Conditional Formatting in columns A and B. And, the some of the dates in columns C and D are text with a leading 0.


Excel 2007
ABCDE
1First NameLastAssign Begin DtAssign Retn DtLevel
2BobJohnson1/7/20135/31/20135
3BobJohnson10/13/200812/31/20132
39BobJohnson1/2/201302/01/20134
40BobJohnson6/1/201311/28/20134
44BobJohnson1/2/201302/01/20132
56BobJohnson05/01/20135/15/20135
57BobJohnson06/01/201310/29/20135
58BobJohnson06/01/201310/29/20135
59BobJohnson11/3/20122/1/20135
Data



I have attempted to solve your every changing request, but, I have far exceeded the normal amount of time I allocate for solving problems/requests from web sites like MrExcel.

Click on the Reply to Thread button, and just put the word BUMP in the post. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0

Forum statistics

Threads
1,216,160
Messages
6,129,215
Members
449,494
Latest member
pmantey13

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