Macro to convert multiple columns in one column without taking input from user and the rows and column value may vary

siddo

Board Regular
Joined
May 26, 2020
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
1​
9​
20​
27​
40​
2​
10​
22​
28​
41​
3​
13​
23​
30​
44​
6​
14​
24​
33​
7​
16​
25​
36​
8​
19​
26​
37​
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
So, do you just want to move all the data into column A?
What row does the data start on?
 
Upvote 0
If my assumptions are correct, and the data starts on row 1, this code would do what you want:
VBA Code:
Sub MoveData()

    Dim lr As Long
    Dim lc As Long
    Dim c As Long
    
   Application.ScreenUpdating = False
    
'   Find last column in row 1 with data
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Exit if only one column of data
    If lc < 2 Then
        Exit Sub
    Else
'       Loop through all columns
        For c = 2 To lc
'           Cut/paste data
            Range(Cells(1, c), Cells(lr, c)).Cut Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        Next c
    End If
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Thank you it works but few things.
1. My Data starts with Row B1 for that I have made adjustments.
2. Just wanted to know is there a way I can specifically define the cell number to paste the data
 
Upvote 0
2. Just wanted to know is there a way I can specifically define the cell number to paste the data
What do you mean?

You don't want to move all the other columns under the first?
Are you saying that you want to paste the list into a whole different location altogether?
If so, do you actually want to "cut" (which actually moves the data), or just "copy" (which will leave the original data alone)?
 
Upvote 0
What do you mean?

You don't want to move all the other columns under the first?
Are you saying that you want to paste the list into a whole different location altogether?
If so, do you actually want to "cut" (which actually moves the data), or just "copy" (which will leave the original data alone)?
I just want to cut the data and paste in to a whole different location...Thank you
 
Upvote 0
I just want to cut the data and paste in to a whole different location...Thank you
OK, that was not clear from your initial post.

Try this:
VBA Code:
Sub MoveData()

    Dim lr As Long
    Dim lc As Long
    Dim c As Long
    Dim ad As String
    
    Application.ScreenUpdating = False
    
'   Prompt user for address to paste to
    ad = InputBox("What is the address of the cell you want to paste the first row of data to?")
    
'   Find last column in row 1 with data
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Loop through all columns, starting with column B
    For c = 2 To lc
'       Cut/paste data
        Range(Cells(1, c), Cells(lr, c)).Cut Range(ad)
'       Find next blank row to paste to
        ad = Range(ad).End(xlDown).Offset(1, 0).Address
    Next c
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Apologies for not being clear in my response....But as I mentioned earlier I do not want input from user so if you could help me paste the offset value in Cells(1,1) of same sheet
 
Upvote 0
Apologies for not being clear in my response....But as I mentioned earlier I do not want input from user so if you could help me paste the offset value in Cells(1,1) of same sheet
I got it covered....Thank you so much for your prompt response.
 
Upvote 0

Forum statistics

Threads
1,216,018
Messages
6,128,307
Members
449,439
Latest member
laurenwydo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top