VBA concatenate the values from two cells and paste into another cell

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
How do I concatenate the values that are in C7 and D7 (With a space inbetween) and paste it into C3?

Code:
Sub PopoulateProducts()

Dim lr As Long

Sheets("Products").Select

'Clear existing data if any
lr = Sheets("Products").Cells(Rows.Count, "A").End(xlUp).Row
If lr > 2 Then Sheets("Parts").Range("A3:D" & lr).ClearContents

'Paste in DataMart Data
Products.Range("A3").Value = Sheets("Step 1").Range("C7")
Products.Range("B3").Value = Sheets("Step 1").Range("D7")

'Need help here
' Products.Range("C3").Value = ?
 
'End If
 
End Sub

[code/]

Thank you!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try:
VBA Code:
Range("C3").Value = Range("C7").Value & " " & Range("D7").Value

Note that references like this:
VBA Code:
Products.Range("A3")...
will not work unless you have defined a worksheet variable named "Products" and set it equal to something.

I recommend you use "Option Explicit" at the top of all your code to make sure you don't use undeclared variables.
 
Upvote 0
Solution
I did define my worksheet as "Products"
Thanks for the help. I will use the Option Explicit

Thank you
 
Upvote 0
I did define my worksheet as "Products"
Where did you do that?
Is it a Global Variable and declared elsewhere (because it is not declared in the code that you posted)?

Note that if you have set "Products" equal to the "Products" sheet, then you do not need to use that sheet qualifier in your range reference in this code, as you have already selected the sheet in the first step:
VBA Code:
Sheets("Products").Select
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,793
Members
449,048
Latest member
greyangel23

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