+ Reply to Thread
Results 1 to 3 of 3

Filling in years

Hybrid View

  1. #1
    Registered User
    Join Date
    09-09-2011
    Location
    OC
    MS-Off Ver
    Excel 2003
    Posts
    1

    Filling in years

    Not sure if its the forum, but here I go.

    Okay, i have some data like
    rb 1999-2003
    rs 1984-1988

    and I want to fill in the years like
    rb 1999
    rb 2000
    rb 2001
    rb 2002
    rb 2003
    rs 1984
    rs 1985
    rs 1986
    rs 1987
    rs 1988

    any ideas?

  2. #2
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Mexico
    Posts
    200

    Re: Tough one here. Filling in years

    Try
    Sub SplitYears()
    FY = Left(Range("A2"), 4)
    LY = Right(Range("A2"), 4)
    NY = LY - FY + 2
    Range("A2") = FY
    Range("A2").AutoFill Range("A2:A" & NY), xlFillSeries
    End Sub

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Tough one here. Filling in years

    @ Armando
    Perhaps you should first, check your idea, and then maybe expand it a little.
    With data in Column A, Row 2 Down and the result in Column B
    Option Explicit
    
    Sub SplitYears()
        Dim LastRow As Long, NextRow As Long, RowNo As Long
        Dim FY As Long, LY As Long, n As Long
        Dim strPrefix As String
    
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
    
        For RowNo = 2 To LastRow
            strPrefix = Left(Range("A" & RowNo), InStr(1, Range("A" & RowNo), " "))
            FY = Mid(Range("A" & RowNo), InStr(1, Range("A" & RowNo), " ") + 1, 4)
            LY = Right(Range("A" & RowNo), 4)
            n = LY - FY
            NextRow = Range("B" & Rows.Count).End(xlUp).Row + 1
            With Range("B" & NextRow)
                .Value = strPrefix & FY
                .AutoFill Range("B" & NextRow & ":B" & NextRow + n), xlFillSeries
            End With
        Next
    End Sub
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1