Results 1 to 10 of 33

Thread: Start & End Number Further Converted

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    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

  2. #2
    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.

  3. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    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.

  4. #4
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Dear Rick Rothstein

    The macro is giving error , I am attaching here a workbook with expected result.
    Attached Files Attached Files

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
  •