Consulting

Results 1 to 4 of 4

Thread: Number ranges

  1. #1

    Unhappy Number ranges

    Hi all,

    Bit of a tough one and not sure if anyone can help. See the attached spreadsheet.

    In column C ("space") is a range of numbers from -13 to 179. What I need to do is to look at the top (-13) and then the bottom number (179) and create a list below (as is red on the excel spreadsheet).

    However, as you will see by the red listing, the spacing of the numbers is every 0.5 - and I would also like a way of the user being able to determine this spacing. The first bit is the priority - so can anyone point me in the right direction?

    Many thanks,

    Chris

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]Public Sub ProcessData()
    Const TEST_COLUMN As String = "C"
    Dim i As Double
    Dim j As Long
    Dim iLastRow As Long
    Dim nStart As Double
    Dim nEnd As Double
    Dim nIncrement As Double


    With ActiveSheet
    iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    nStart = .Cells(2, TEST_COLUMN).Value
    nEnd = .Cells(iLastRow, TEST_COLUMN).Value

    If IsNumeric(nStart) And IsNumeric(nEnd) Then
    nIncrement = InputBox("Supply step value")

    If IsNumeric(nIncrement) Then
    j = iLastRow + 1

    For i = nStart To nEnd Step nIncrement
    .Cells(j, TEST_COLUMN).Value = i
    j = j + 1
    Next i
    Else
    MsgBox "Invalid step value"
    End If

    Else
    MsgBox "Invalid start/end value"
    End If
    End With
    End Sub
    [/vba]

    Edited 15-Jun-07 by geekgirlau. Reason: post went crazy - competing for world's longest single line of code!!!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thank you so much.

    One little problem...

    For i = nStart To nEnd
    Step nIncrement.Cells(j, TEST_COLUMN).Value = i
    j = j + 1

    It keeps returning nIncrement as a "invalid qualifier" - any ideas?

    thanks

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try again

    [vba]

    Public Sub ProcessData()
    Const TEST_COLUMN As String = "C"
    Dim i As Double
    Dim j As Long
    Dim iLastRow As Long
    Dim nStart As Double
    Dim nEnd As Double
    Dim nIncrement As Double

    With ActiveSheet

    iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    nStart = .Cells(2, TEST_COLUMN).Value
    nEnd = .Cells(iLastRow, TEST_COLUMN).Value
    If IsNumeric(nStart) And IsNumeric(nEnd) Then

    nIncrement = InputBox("Supply step value&quot
    If IsNumeric(nIncrement) Then

    j = iLastRow + 1
    For i = nStart To nEnd Step nIncrement

    .Cells(j, TEST_COLUMN).Value = i
    j = j + 1

    Next i
    Else

    MsgBox "Invalid step value"
    End If
    Else

    MsgBox "Invalid start/end value"
    End If
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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