PDA

View Full Version : Solved: COmbine columns



ahvmtv
01-19-2006, 09:45 AM
:banghead: Hello. I have a problem I need to resolve.
I have 2 worksheets with data. (aprox 40 columns each)
The names of the columns are 1-a 2-a 3-a 4-a 5-a, etc... on one of the worksheets and 1-b, 2-b, 3-b, 4-b, etc... on the other worksheet. What I need to do is a new worksheet with columns combining the data of each of the worksheets . I mean I need a new worksheet with this information order
1-a, 1-b, 2-a, 2-b, 3-a, 3-b, etc... (I would like to get a quick solution, no just copy and paste because the data base is so big, so it takes a lof of time)

Any suggestion?
I really appreciate you help..

austenr
01-19-2006, 10:06 AM
Try the attached workbook.

To use, select the cells in the columnsyou want to combine. For example, if you wanted to combine A1,B1,C1 the select A1:C1, then run the macro. Will put all cell contents in the left most column.

mdmackillop
01-19-2006, 10:35 AM
Hi,
Welcome to VBAX
Try the following. It assumed Data in Sheet1 and Sheet2, combining into Sheet3. It also assumes equal data columns in both sheets
Option Explicit

Sub JoinData()
Dim i As Long, Cols As Long

Application.ScreenUpdating = False
Sheets("Sheet1").Activate
Cells.Copy
Sheets("sheet3").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Cols = Sheets("Sheet3").[IV1].End(xlToLeft).Column
For i = Cols To 2 Step -1
Cells(1, i).EntireColumn.Insert
Next
For i = 1 To Cols
Sheets("Sheet2").Activate
Columns(i).Copy
Sheets("sheet3").Activate
Cells(1, 2 * i).Select
ActiveSheet.Paste
Next
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

austenr
01-19-2006, 10:55 AM
Boy I misread that one!!

ahvmtv
01-19-2006, 11:11 AM
Thank you for your help.
I have a problem on (Range("A1").Select ), it is giving me error 1004. Can you help me to fix it please!!!!

mdmackillop
01-19-2006, 11:37 AM
Can you post your workbook with sanitized data. To post it, use Manage Attachments which you'll find in the Go Attached option.

ahvmtv
01-19-2006, 12:09 PM
Ok, let's say I have info on worksheets 1 and 2.
I need to copy all that information to worksheet 3 in this order:
data on:
a-1 a-2 b-1 b-2 c-1 c-2, etc... in different columns!!

Thank you

mdmackillop
01-19-2006, 12:41 PM
I can see no problem with the code and have to suspect some workbook corruption. Try this version. I added a button for ease of use and a final A1 select, otherwise things are the same.

ahvmtv
01-20-2006, 12:44 PM
I really appreciate your help. It worked fantastic.

mdmackillop
01-20-2006, 06:54 PM
Glad to help out.

If you're happy with the answer, please mark the thread solved usiing the thread tools dropdown, or else let us know of any queries
Regards
MD