Hi everyone. I'm new to using macros so would appreciate some help. I want to join multiple columns of data and retain the original formatting. Some columns contain text, some text and numbers and one column has the time. The VBA code I'm using joins the columns appropriately but the time is converted to decimals. i've tried all the different Paste Special commands (xl PasteValues, xlPasteValuesandNumberFormats etc.) but nothing seems to work.
Here is the VBA code:
Sub SpecialConcat()
Dim lastRow As Long
Dim wsData As Worksheet
'Where is the data?
Set wsData = Worksheets("RSG New Download")
Application.ScreenUpdating = False
With wsData
'Find where our data ends
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("J1").EntireColumn.Insert
With .Range("J2:J" & lastRow)
.Formula = "=F2 & "" "" & G2 & "" "" & H2 & "" "" & I2 & "" "" & ""EDT"""
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
.Range("F:I").Delete
End With
Application.ScreenUpdating = True
End Sub
This is the original data:
I want to join the 4 columns so the entries looks like: HMB430H1F LEC0101 Wednesday 6:00 PM EDT
This is the result I get when I run the code:
Thanks!
Cheryl
Here is the VBA code:
Sub SpecialConcat()
Dim lastRow As Long
Dim wsData As Worksheet
'Where is the data?
Set wsData = Worksheets("RSG New Download")
Application.ScreenUpdating = False
With wsData
'Find where our data ends
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("J1").EntireColumn.Insert
With .Range("J2:J" & lastRow)
.Formula = "=F2 & "" "" & G2 & "" "" & H2 & "" "" & I2 & "" "" & ""EDT"""
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
.Range("F:I").Delete
End With
Application.ScreenUpdating = True
End Sub
This is the original data:
HMB430H1F | LEC0101 | Wednesday | 6:00 PM |
CSB343 | Lec0101 | Saturday | 1:00 PM |
ENG273Y1 Y | LEC5101 | Wednesday | 4:00 PM |
I want to join the 4 columns so the entries looks like: HMB430H1F LEC0101 Wednesday 6:00 PM EDT
This is the result I get when I run the code:
HMB430H1F LEC0101 Wednesday 0.75 EDT |
CSB343 Lec0101 Saturday 0.541666666666667 EDT |
ENG273Y1 Y LEC5101 Wednesday 0.666666666666667 EDT |
Thanks!
Cheryl