Merge data from multiple columns into one column

cplus

I have the following:
enter image description here


I am using @BigBobby's answer to achieve this:

Sub MoveData()
Range("H5:H99").ClearContents
START_ROW = 5
START_COL = 1
STEP_COL = 2
OUTPUT_ROW = 5
OUTPUT_COL = 8
Limit_Col = 9

Row = START_ROW
Col = START_COL
Out_Row = OUTPUT_ROW
While Col < Limit_Col
    While Cells(Row, Col).Value <> ""
        Cells(Out_Row, OUTPUT_COL).Value = Cells(Row, Col).Value
        Out_Row = Out_Row + 1
        Row = Row + 1
    Wend
    Row = START_ROW
    Col = Col + STEP_COL
Wend
End Sub


But as you see, I expect to get those values which appear after a blank cell in the columns. But this code fails to pull those cells highlighted in yellow.
How to modify this code to pull all of the data which may appear after one or several blank cells?

Shauno_88

Adjust this code:

While Cells(Row, Col).Value <> ""
    Cells(Out_Row, OUTPUT_COL).Value = Cells(Row, Col).Value
    Out_Row = Out_Row + 1
    Row = Row + 1
Wend

For:

Do until row > Cells(65536, Col).End(xlUp).Row
    Cells(Out_Row, OUTPUT_COL).Value = Cells(Row, Col).Value
    Out_Row = Out_Row + 1
    Row = Row + 1
Loop

This essentially checks to see if the row has passed the last row with data, and if it has, it moves onto the next column.

Edit

To not copy across the blank cells use this:

    Do until row > Cells(65536, Col).End(xlUp).Row
        If Cells(Row, Col).Value <> "" then
            Cells(Out_Row, OUTPUT_COL).Value = Cells(Row, Col).Value
            Out_Row = Out_Row + 1
        End If
        Row = Row + 1
    Loop

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Merge multiple columns into one and rename values based on column it came from

Merge multiple columns into one column with multiple rows

How to merge multiple columns values into one column?

Merge multiple google spreadsheet columns into one column

Merge multiple columns into one with index column in PySpark

How can I render data from multiple columns into one column?

Copy data from one column to multiple columns specifying their name

Count of data from one column into multiple columns with MySQL?

Excel interprets multiple columns from Notepad data as one column

how to put data from multiple columns into one column in excel

Create multiple columns from one column (with the same data)

Split data from one column into multiple columns and rows

Merge multiple columns data into one pandas

Merge multiple columns from different tables into one

Data Preparation Advanced Pandas Melt Multiple Column Sets. Merge some Columns to make them one

Merge columns into one column

Merge multiple columns values in one column in one row Oracle SQL

How do I merge pandas df with multiple columns using one key from another column?

Merge contents from three dataframes into one column in R (across multiple columns)

Merge multiple columns into one

Python Pandas: Merge Columns of Data Frame with column name into one column

spread json data in one column to multiple columns

SQL: Convert Data For One Column To Multiple Columns

data in multiple columns in one single column or row

Mix data of multiple columns into one column

Join multiple columns from one data frame to single column from another without multiple join operation, in pyspark

Python Dataframe Merge Boolean Columns Data into One Column Data

How to merge several rows with event data from multiple columns when based on unique character column?

How to select multiple Integer data from different columns and merge them into single column of array integer