![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 75
|
I looked through the search and could not find excatly whatI was looking for here.
What I am trying to do is merge data from 2 different cells into one cell. I have tried to use the merge cell command in excel but it drops the data from the second cell or cells. Kind of defeats the purpose. I tried to record a macro to do this but it uses the specific cell data, and my prblem is each cell has different data that I want to merge. I know it can be done this way, just need to use the right variables. Anyone out there have the code out there for this. Any help would be much appreciated. |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Posts: 75
|
Here is the answer to my own question, For anyone who wondered how it could be done here is one one way
Merge cell Data() ' Dim CellData As String Dim CellData1 As String Sheets(1).Cells(1, 2).Select CellData = Sheets(1).Cells(1, 2) strfile = CellData ActiveCell.FormulaR1C1 = strfile Sheets(1).Cells(1, 1).Select CellData1 = Sheets(1).Cells(1, 1) strfile1 = CellData1 ActiveCell.FormulaR1C1 = CellData1 & CellData End Sub |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Location: Arkansas
Posts: 358
|
A easy way to merge data is with the comand ( Concatenate ). Which will merge two or more fields.
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Posts: 75
|
Here is the final code I came up with that works quite well. Only one nit picky problem. Is there way to put s space between the merged data?
Sub merge_cell_data() ' ' Macro1 Macro ' Macro recorded 3/21/2002 by ctemp ' ' Dim CellData As String Dim CellData1 As String Dim MergedData As String For i = 0 To 500 CellData = Sheets(1).Cells(1 + i, 2) CellData1 = Sheets(1).Cells(1 + i, 1) MergedData = CellData1 & CellData If CellData = blank Then End Sheets(1).Cells(1 + i, 6).Select ActiveCell.FormulaR1C1 = MergedData Next End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|