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

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,915
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,024
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,915
Office Version
  1. 365
Platform
  1. Windows
I did define my worksheet as "Products"
Thanks for the help. I will use the Option Explicit

Thank you
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,024
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,147,451
Messages
5,741,188
Members
423,647
Latest member
lyanndominique

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
Top