+ Reply to Thread
Results 1 to 4 of 4

I am wanting excel to split years out into 2 columns

Hybrid View

  1. #1
    Registered User
    Join Date
    02-05-2021
    Location
    doncaster
    MS-Off Ver
    excel 2013
    Posts
    1

    I am wanting excel to split years out into 2 columns

    Cell b2

    years in the sheet

    2005 , 2006 , 2007 , 2008 , 2009 , 2010 , 2011 , 2012 , 2013 , 2014 , 2015 , 2016 , 2017 , 2018 , 2019 , 2020

    cell c2

    years in the sheet from to

    2005-2020

    cell d2

    years to include

    2006-2009

    cell e2

    includeyears auto fill

    should read 2006 , 2007 , 2008 , 2009

    cell f2

    excludeyears auto fill

    2005 , 2010 , 2011 , 2012 , 2013 , 2014 , 2015 , 2016 , 2017 , 2018 , 2019 , 2020
    Attached Files Attached Files

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,640

    Re: I am wanting excel to split years out into 2 columns

    Hi
    could you be a little more explicit please?

  3. #3
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: I am wanting excel to split years out into 2 columns

    This VBA sub should give you roughly what you need...
    Sub Separate_Years()
    
    Dim Str1 As String
    Dim Str2 As String
    
    Dim LastRow As Long
    Dim Yr As Variant
    
    Dim Y1 As Integer
    Dim Y2 As Integer
    Dim i As Integer
    Dim j As Integer
    Dim CPos As Integer
    
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    For i = 2 To LastRow
    
        Y1 = Left(Range("C" & i).Value, InStr(Range("C" & i).Value, "-") - 1)
        Y2 = Right(Range("C" & i).Value, Len(Range("C" & i).Value) - InStr(Range("C" & i).Value, "-"))
        
        Yr = Split(Range("B" & i), ",")
        For j = 0 To UBound(Yr)
            If Yr(j) >= Y1 And Yr(j) <= Y2 Then
                Str1 = Str1 & "," & Yr(j)
            Else
                Str2 = Str2 & "," & Yr(j)
            End If
        Next j
        Str1 = Mid(Str1, 2)
        Str2 = Mid(Str2, 2)
        Range("E" & i) = Str1
        Range("F" & i) = Str2
        Str1 = ""
        Str2 = ""
        
    Next i
    End Sub

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: I am wanting excel to split years out into 2 columns

    Please try at
    E2
    =MID(LEFT(B2,IFERROR(FIND(RIGHT(C2,4),B2)+3,999)),IFERROR(FIND(LEFT(C2,4),B2),1),999)

    F2
    =SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(B2,E2,),",",))," "," , ")
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Split years into weeks and get a date
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-18-2018, 11:39 AM
  2. Wanting to split one cell into multiple rows while keeping data next to it
    By Trnecessary in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-05-2018, 04:13 PM
  3. Split number of months from years
    By ardhuru in forum Excel General
    Replies: 10
    Last Post: 07-05-2017, 10:45 AM
  4. Split Start End date into multiple years
    By tos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2016, 06:42 AM
  5. [SOLVED] Wanting to do SUMIF across multiple columns
    By Vx22B012 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-30-2012, 11:50 AM
  6. Replies: 1
    Last Post: 12-05-2005, 08:35 AM
  7. [SOLVED] wanting to know width of several columns for copying
    By Sunantoro in forum Excel General
    Replies: 3
    Last Post: 08-25-2005, 06:05 AM

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