+ Reply to Thread
Results 1 to 3 of 3

Excel Macro - Combined the text in different cells to a new cell with many variables

  1. #1
    Registered User
    Join Date
    10-11-2017
    Location
    Hong Kong
    MS-Off Ver
    2019
    Posts
    55

    Excel Macro - Combined the text in different cells to a new cell with many variables

    Hi all excel macro experts,

    I face difficulties in writing this macro. The situation is I have a raw excel data for some item and its remark. For example, column A is Item No., column B is Remarks, see picture below. How can I write this macro to combine the remarks to column C if they are the same item no. in column A? Please note that the combine text need to place on the first row of the different item no.

    I try to write the below macro but it seems doesn't work because it didn't know how many rows item no. have (5377 have 5 rows, 5503 have 4 rows) in order to combine the correct results in column C. The result I want is at the below picture. Many thanks if any experts can help me!

    Sub combine()

    Dim a, b As Integer

    a = 3
    b = 2

    Do

    If Cells(b + 1, 1).Value <> Cells(b, 1).Value Then

    Cells(b, 3).Value = Cells(b - a - 3, 2) & Cells(b - a - 2, 2) & Cells(b - a - 1, 2) & Cells(b - a, 2) & Cells(b, 2)

    End If

    b = b + 1

    Loop Until Cells(b, 1).Value = ""

    End Sub

    macro.jpg

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel Macro - Combined the text in different cells to a new cell with many variables

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    10-11-2017
    Location
    Hong Kong
    MS-Off Ver
    2019
    Posts
    55

    Re: Excel Macro - Combined the text in different cells to a new cell with many variables

    Quote Originally Posted by AlphaFrog View Post
    Please Login or Register  to view this content.
    Thanks, it works well! Once again appreciate your effort!!

+ 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] Sending result of Looping text combined down a column, to a cell
    By Rabbitoh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2017, 01:30 AM
  2. Copy and pasting cells into a combined cell. - VBA
    By PashStratton in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2017, 12:07 PM
  3. [SOLVED] Sum two text boxes and write to a cell in excel by the variables
    By jwalma in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-06-2014, 12:34 AM
  4. [SOLVED] Using Text to Columns combined with Transpose in a macro
    By Bax in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-01-2013, 04:12 AM
  5. can the text of two cells be combined with merge
    By jamie.c in forum Excel General
    Replies: 9
    Last Post: 01-20-2010, 10:23 AM
  6. [SOLVED] text and number combined in a cell
    By TimN in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-11-2006, 06:05 PM
  7. [SOLVED] How can I remove diff. numbers from a cell combined with text
    By Greg in forum Excel General
    Replies: 5
    Last Post: 02-28-2006, 04:10 PM

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