Page 1 of 3 123 LastLast
Results 1 to 10 of 33

Thread: Start & End Number Further Converted

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14

    Start & End Number Further Converted

    Hi

    I need you help regarding to attached file example data , there are different start and end numbers with each qty equal to 400 , I want them to be further converted into Starat and End Range as mentioned in example attached sheet.

    Thanks in advance
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Your first set is clear. Can be done. In your second set, how do you decide that a series has started and ended?

  3. #3
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Quote Originally Posted by Excel Fox View Post
    Your first set is clear. Can be done. In your second set, how do you decide that a series has started and ended?
    Because data is sorted and in ascending order you see the same in second example start and end range data is matched a and Qty of each range is qual to first example

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by Excel Fox View Post
    Your first set is clear. Can be done. In your second set, how do you decide that a series has started and ended?
    I think the question Excel Fox wants to know is... will the second set always be totalling to 100000 or less (you don't say that in its header)?

    I have a question of my own for you... Is the 400 shown down Column C always 400 in every cell or will those numbers vary down the column in "real life"?

  5. #5
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Quote Originally Posted by Rick Rothstein View Post
    I think the question Excel Fox wants to know is... will the second set always be totalling to 100000 or less (you don't say that in its header)?

    I have a question of my own for you... Is the 400 shown down Column C always 400 in every cell or will those numbers vary down the column in "real life"?
    Thanks for your reply, second set can not always be totalling to 100000, it might be less
    And column c is always 400, you can say Qty or count is always equal to 400 in Column c
    Last edited by ayazgreat; 04-18-2012 at 11:16 PM.

  6. #6
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by ayazgreat View Post
    Thanks for your reply, second set can not always be totalling to 100000, it might be less
    Okay, if that is the case, then how do we know what number to total up to in order to determine the ranges? Is the number being stored in a cell somewhere (if so, where)?

  7. #7
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Quote Originally Posted by Rick Rothstein View Post
    Okay, if that is the case, then how do we know what number to total up to in order to determine the ranges? Is the number being stored in a cell somewhere (if so, where)?
    All numbers are stored from column a to b with their Qty in column c and this the query to be developed in code to to determine start range and end range of the same number as I mentioned in attached sheet in two different examples.

  8. #8
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Are you saying that you now want to generate the input from the output?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  9. #9
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Yes Kris, you are absolultly right now I want each 20000 range (col a to c) to be converted into 400 range of different series.

  10. #10
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by ayazgreat View Post
    Yes Kris, you are absolultly right now I want each 20000 range (col a to c) to be converted into 400 range of different series.
    Okay, give the following macro a try. You will be asked 3 questions. The first question asks you to select the cell with the first "Start Range" number in it. In your example case, that would be cell A2 or cell F3 or cell J3 depending on which chart you are going to reference. The second question asks you to input the quantity to break the chart out by (same as asked for in my original code). The third question asks you to select the first cell to start the chart at (again, same as asked for in my original code).

    Code:
    Sub StartEndRanges()
      Dim X As Long, TargetQty As Long, StartRow As Long, LastRow As Long, RangeStart As Long, RangeEnd As Long
      Dim TotalQty As Double, NumberOfFullRows As Long, StartRangeCell As Range, DestinationStartCell As Range
      On Error GoTo NoCell
      Set StartRangeCell = Application.InputBox("Select 1st Start Range cell in table to convert from.", Type:=8)
      StartRow = StartRangeCell.Row
      LastRow = StartRangeCell.End(xlDown).Row
      RangeStart = StartRangeCell.Value
      RangeEnd = StartRangeCell.Offset(LastRow - StartRow, 1).Value
      TotalQty = WorksheetFunction.Sum(StartRangeCell.Offset(, 2).Resize(LastRow - StartRow + 1))
      TargetQty = Application.InputBox("What quantity do you want for each ranges", Type:=1)
      If TargetQty <= 0 Or TargetQty Like "*[!0-9]*" Then
        MsgBox "The number """ & TargetQty & """ is not valid!", vbExclamation
        Exit Sub
      End If
      Set DestinationStartCell = Application.InputBox("Please select the start cell for output?", Type:=8)
      On Error GoTo 0
      NumberOfFullRows = TotalQty \ TargetQty
      With DestinationStartCell
        .Resize(, 3).Merge
        .Value = "Result After Macro: " & TargetQty & " or less"
        .HorizontalAlignment = xlHAlignCenter
        .Interior.ColorIndex = 48
        .Font.Bold = True
        With .Offset(1).Resize(, 3)
          .Value = Array("Start Range", "End Range", "Qty")
          .Interior.ColorIndex = 15
          .HorizontalAlignment = xlHAlignCenter
          .Font.Bold = True
          .ColumnWidth = 15
        End With
        .Resize(NumberOfFullRows).Offset(2, 2).Value = TargetQty
        If TotalQty - NumberOfFullRows * TargetQty Then
          Cells(.Row + NumberOfFullRows + 2, .Column + 2).Value = TotalQty - NumberOfFullRows * TargetQty
        End If
        For X = 0 To NumberOfFullRows + (TotalQty = NumberOfFullRows * TargetQty)
          Cells(.Row + X + 2, .Column).Value = RangeStart + X * TargetQty
          Cells(.Row + X + 2, .Column + 1).Value = Cells(.Row + X + 2, .Column).Value + _
                                                   Cells(.Row + X + 2, .Column + 2).Value - 1
        Next
        If TotalQty > NumberOfFullRows * TargetQty Then
          With Cells(.Row + NumberOfFullRows + 2, .Column + 1)
            .Value = .Value + Cells(.Row + NumberOfFullRows + 2, .Column + 2).Value
          End With
        End If
      End With
    NoCell:
    End Sub
    Last edited by Rick Rothstein; 04-24-2012 at 05:35 AM.

Similar Threads

  1. Replies: 5
    Last Post: 06-15-2013, 12:40 PM
  2. VBA - Find Last End Value
    By ivandgreat in forum Excel Help
    Replies: 3
    Last Post: 05-02-2013, 10:37 AM
  3. Date Format From Start Day To End Day
    By PcMax in forum Excel Help
    Replies: 2
    Last Post: 03-10-2013, 02:07 PM
  4. Replies: 17
    Last Post: 12-18-2012, 04:15 PM
  5. Week Number And Week Start Day of Week
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 10-24-2011, 07:33 PM

Posting Permissions

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