Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 107785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:48:31+00:00 2026-05-11T01:48:31+00:00

I had a similar question answered Here There is a slight twist to the

  • 0

I had a similar question answered Here

There is a slight twist to the scenario and hoping the macro can be changed slightly. Any help is appreciated.

Based on this Data:

    <- A (Category) ->   <- B (Items) ->  1   Cat1                 a,b, c 2   Cat2                 d 3   Cat3                 e 4   Cat4                 f, g 

I need this:

    <- A (Category) ->   <- B (Items) ->  1   Cat1                 a 2   Cat1                 b 3   Cat1                 c 4   Cat2                 d 5   Cat3                 e 6   Cat4                 f 7   Cat4                 g 

This is the existing Macro:

Option Explicit Sub Macro1()     Dim fromCol As String     Dim toCol As String     Dim fromRow As String     Dim toRow As String     Dim inVal As String     Dim outVal As String     Dim commaPos As Integer      ' Copy from column A to column B.'     fromCol = 'A'     toCol = 'B'     fromRow = '1'     toRow = '1'      ' Go until no more entries in column A.'     inVal = Range(fromCol + fromRow).Value     While inVal <> ''          ' Go until all sub-entries used up.'         While inVal <> ''             Range(fromCol + fromRow).Select              ' Extract each subentry.'             commaPos = InStr(1, inVal, ',')             While commaPos <> 0                  ' and write to output column.'                 outVal = Left(inVal, commaPos - 1)                 Range(toCol + toRow).Select                 Range(toCol + toRow).Value = outVal                 toRow = Mid(Str(Val(toRow) + 1), 2)                  ' Remove that sub-entry.'                 inVal = Mid(inVal, commaPos + 1)                 While Left(inVal, 1) = ' '                     inVal = Mid(inVal, 2)                 Wend                 commaPos = InStr(1, inVal, ',')             Wend              ' Get last sub-entry (or full entry if no commas).'             Range(toCol + toRow).Select             Range(toCol + toRow).Value = inVal             toRow = Mid(Str(Val(toRow) + 1), 2)             inVal = ''         Wend          ' Advance to next source row.'         fromRow = Mid(Str(Val(fromRow) + 1), 2)         Range(fromCol + fromRow).Select         inVal = Range(fromCol + fromRow).Value     Wend End Sub 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:48:32+00:00Added an answer on May 11, 2026 at 1:48 am

    I think this will work for you:

    Sub ExpandData()     Const FirstRow = 2     Dim LastRow As Long     LastRow = Range('A' & CStr(Rows.Count)).End(xlUp).Row      ' Get the values from the worksheet     Dim SourceRange As Range     Set SourceRange = Range('A' & CStr(FirstRow) & ':B' & CStr(LastRow))      ' Get sourcerange values into an array     Dim Vals() As Variant     Vals = SourceRange.Value      ' Loop through the rows in the array and split each comma-delimited list of items and put each on its own row     Dim ArrIdx As Long     Dim RowCount As Long     For ArrIdx = LBound(Vals, 1) To UBound(Vals, 1)          Dim CurrCat As String         CurrCat = Vals(ArrIdx, 1)          Dim CurrList As String         CurrList = Replace(Vals(ArrIdx, 2), ' ', '')          Dim ListItems() As String         ListItems = Split(CurrList, ',')          Dim ListIdx As Integer         For ListIdx = LBound(ListItems) To UBound(ListItems)              Range('A' & CStr(FirstRow + RowCount)).Value = CurrCat             Range('B' & CStr(FirstRow + RowCount)).Value = ListItems(ListIdx)             RowCount = RowCount + 1          Next ListIdx      Next ArrIdx  End Sub 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer For best compatibility with Rails, you would probably save yourself… May 11, 2026 at 11:33 am
  • added an answer Once you have set up the index array, you can… May 11, 2026 at 11:33 am
  • added an answer You really don't want to synchronize on an Integer, since… May 11, 2026 at 11:33 am

Related Questions

I had a similar question answered Here There is a slight twist to the
I had a discussion with some colleagues mentioning that there are not too many
I had a plugin installed in Visual Studio 2008, and it created some extra
I had a discussion with a developer earlier today re identifying TCP packets going
I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a
I had a discussion a few weeks back with some co-workers on refactoring, and
I had a problem that was partially solved. To explain it quickly : I
I had a little discussion with a friend about the usage of collections in
I had a nasty typo that wasted my time and my colleague's time, it
I had a VBA project in outlook with a few email macros - but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.