Results 1 to 10 of 33

Thread: Start & End Number Further Converted

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    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)?

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

  3. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Give the following macro a try and see if you can make use of it...

    Code:
    Sub StartEndRanges()
      Dim X As Long, TargetNumber As Long, NumberOfRows As Long, LastRow As Long, Increment As Long, DestinationStartCell As Range
      Const FixedQty As Long = 400
      Const StartRow As Long = 2
      TargetNumber = Application.InputBox("What quantity total do you want ranges for (note... must be a multiple of 400)?", Type:=1)
      If TargetNumber = 0 Or TargetNumber Mod 400 <> 0 Then
        MsgBox "The number """ & TargetNumber & """ is not valid!", vbExclamation
      End If
      On Error GoTo NoCell
      Set DestinationStartCell = Application.InputBox("Please select the start cell for output?", Type:=8)
      LastRow = Cells(Rows.Count, "A").End(xlUp).Row
      NumberOfRows = TargetNumber \ FixedQty
      With DestinationStartCell
        .Resize(, 3).Merge
        .Value = "Result After Macro: " & TargetNumber & " 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
      End With
      For X = StartRow To LastRow Step NumberOfRows
        DestinationStartCell.Offset(2 + Increment).Value = Cells(X, "A").Value
        DestinationStartCell.Offset(2 + Increment).Offset(, 1).Value = Cells(X + NumberOfRows - 1, "B").Value
        DestinationStartCell.Offset(2 + Increment).Offset(, 2).Value = WorksheetFunction.Sum(Cells(X, "C").Resize(NumberOfRows))
        Increment = Increment + 1
      Next
      DestinationStartCell.Offset(1 + Increment).Offset(, 1).Value = Cells(LastRow, "B").Value
    NoCell:
    End Sub
    Note: The code will ask you for the quantity total you want the list broken down by (you would 20000 for your first chart, 100000 for your second chart) and the starting cell (top left corner) to output the chart to (which does not have to be on Row 1 if you do not want it to be).

  4. #4
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Thank you very Rick Rothstein
    It works really great , more than my expectation.

  5. #5
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by ayazgreat View Post
    Thank you very Rick Rothstein
    It works really great , more than my expectation.
    You are quite welcome... I am glad I was able to be of help to you.

  6. #6
    Member ayazgreat's Avatar
    Join Date
    Mar 2012
    Posts
    86
    Rep Power
    14
    Rick Rothstein
    I want to ask something more regarding above post that if Column a & b Start & End number but Column C Qty of each range is 20000 and I want to convert each range from col a to c same into 400 as in previouse code we have qty in col c and we can convert them to 20000 or more but Now case is oposite it.

    Thanks in advance

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
  •