Using VBA to concatenate two columns

Belinda

Board Regular
Joined
Apr 5, 2004
Messages
61
Hello,

I have an Excel table that has a fixed number of columns but the number of rows can vary depending on the data update. The columns have a header row.

I want to use VBA code to concatenate the text contents of Column F and H with an underscore in between and place the contents in Column J.

E.g. Cell F2 has "FC TAB" and Column H2 has "Allegra Plus". The result in Cell J2 would be "FC TAB_Allegra Plus"

Thank you.
 
I think the compatibility fix for IE11 might have worked, so let's give it a go.
I'm trying to convert a spreadsheet of weather station observations into a format that will work with WindRose3 (Enviroware). The program does what it says on the tin - rather well, actually.
The conversions are really quite simple, as can be seen by this code, which works properly and I think is self explanatory:
Code:
Rowcount = Cells(1048576, 2).End(xlUp).Row
For Count = 2 To Rowcount
Cells(Count, 4) = Cells(Count, 4) * 0.44704
Cells(Count, 6) = Cells(Count, 6) * 0.44704
Cells(Count, 5) = Application.WorksheetFunction.VLookup(Cells(Count, 5), Worksheets("Wind").Range("B4:C24"), 2)
Cells(Count, 7) = Application.WorksheetFunction.VLookup(Cells(Count, 7), Worksheets("Wind").Range("B4:C24"), 2)
Cells(Count, 1) = Format(Cells(Count, 2), "dd/mm/yyyy") & " " & Format(Cells(Count, 3), "hh:mm")
Next

Column 2 contains observation dates in format "dd/mm/yyyy" format.
But as an exercise I'd like convert this to range handling rather than cell by cell manipulation, if only because that is so much faster.

I've got most of this converted nicely:
Code:
Dim rngData     As Range
Set rngData = Range(Cells(2, 4), Cells(Rowcount, 4))
        rngData = Evaluate(rngData.Address & "*0.44704")
        rngData.NumberFormat = "0.00"
    Set rngData = Range(Cells(2, 6), Cells(Rowcount, 6))
        rngData = Evaluate(rngData.Address & "*0.44704")
        rngData.NumberFormat = "0.00"
    Set rngData = Range(Cells(2, 5), Cells(Rowcount, 5))
    rngData = Application.WorksheetFunction.VLookup(rngData, Worksheets("Wind").Range("B4:C21"), 2, False)
    Set rngData = Range(Cells(2, 7), Cells(Rowcount, 7))
    rngData = Application.WorksheetFunction.VLookup(rngData, Worksheets("Wind").Range("B4:C21"), 2, False)

But how do you convert the concatenation line to work properly?
Code:
Range("A2:A" & Rowcount).Value = Evaluate("=B2:B" & Rowcount & "&""""&" & "C2:C" & Rowcount)
Gives dates that are far in the future
Code:
Range("A2:A" & Rowcount).Formula = "=B2 & C2"
Gives apparent Julian based numbers which have obviously converted the date section using "mm/dd/yyyy" format.

So how/can you make this conversion using Range handling?
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
So, all sorted in relation to typing responses in the forum now?
 
Upvote 0
I know this thread is ancient but it looks like you are still very active here. I wanted to use this snippet of code for my project but wanted to use R1C1 notation so I can loop through this more than once. Nothing seems to work for me. Here is what I am trying: (just trying Column "C" for now before inserting variables)

Code:
With Range(Cells(1, 3), Range(Cells(rows.Count, 3)).End(xlUp))
        .Offset(, 2).Value = Evaluate(.Address & " & " & .Offset(, 1).Address)
End With

I thought I could just exchange the A1 notation with Cells but I get run-time error '1004': Method 'Range' of object '_Global' failed.

Any help or even a resource that might help would be greatly appreciated. Thanks!
 
Upvote 0
Try
Code:
With Range(Cells(1, 3), Cells(Rows.Count, 3).End(xlUp))
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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