Combining Cells

inafitz

New Member
Joined
Jul 20, 2018
Messages
3
Hello there, thank you for taking the time to read my question.

I need to combine two cells via VBA.

For instance, if I'm in cell ES128 I need to combine ES1 and A126. (i.e. =ES1&A128)

In a nutshell, whatever cell I'm in, I need to combine row 1 of the active column and column A of the active row.

So for another instance, if I'm in cell DR272 I need to combine DR1 and A272. (i.e. =DR1&A272).

My VBA skills are not good enough to do this myself, I would appreciate if someone could help.

Kind Regards.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This is sheet code for the sheet you want cells combined when you change the activecell.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set Target = Target(1)
Target.Value = Me.Cells(1, Target.Column) & Me.Cells(Target.Row, "A")
End Sub
 
Upvote 0
Try this out in the worksheet code

***Important*** Make sure you save the file first as this will continue to edit all cells infinitely and you might not liike what it did

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Value = Cells(1, Target.Column).Value & Cells(Target.Row, 1).Value
End Sub
 
Upvote 0
.


Code:
Option Explicit


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Cells(Target.Row, 1).Value = 0 Or Cells(1, Target.Column).Value = 0 Then
    Exit Sub
Else
    Target.Value = Cells(1, Target.Column).Value + Cells(Target.Row, 1).Value
End If


End Sub

If there is no value in Col A for any row or no value in Row 1 of the active Col, the action exits the macro.

Download : https://www.amazon.com/clouddrive/share/PdnHLx8YVZdk0EGXGl9PesmLMrX7KF2wQlCSjms3JBM
 
Last edited:
Upvote 0
Thank you to everyone that responded.

My sincere apologies, I've had a little play around, but I don't understand Private Subs.

I just needed a bit of VBA to add in to a current macro.

Apologies again.
 
Upvote 0
Maybe
Code:
Dim Cl As Range
Set Cl = Range("ES123")
Cl.Value = Cells(1, Cl.Column) & Cells(Cl.Row, 1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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