VBA to insert column and write concatenation formula

nirvehex

Active Member
Joined
Jul 27, 2011
Messages
493
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to insert a column in between columns A & B. Then in the new B1 I would like to write text that says "Unique Key"

Then in cells b2:end of data set I want to write =concatenate(F1,"-",R1,"-",T1) and have it copy this formula all the way down column B until the data stops in those other columns.

I have the first part of the code which inserts a column, the rest is hard for me:

Here's what I have so far:

Code:
Sub sbInsertingColumns() 
    Dim x As Long 
    Range("B1").EntireColumn.Insert 
End Sub

Any ideas?

Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,907
Office Version
  1. 365
Platform
  1. Windows
Try:
Code:
Sub Macro1()

Dim x As Long
Dim sConc As String

Application.ScreenUpdating = False

Range("B1").EntireColumn.Insert shift:=xlToRight
Range("B1").Value = "Unique Key"
x = Range("A" & Rows.Count).End(xlUp).Row
sConc = "=F2&""-""&R2&""-""&T2"
Range("B2").Resize(x - 1).Formula = sConc

Application.ScreenUpdating = True


End Sub
 
Upvote 0

nirvehex

Active Member
Joined
Jul 27, 2011
Messages
493
Office Version
  1. 365
Platform
  1. Windows
Thanks!

Try:
Code:
Sub Macro1()

Dim x As Long
Dim sConc As String

Application.ScreenUpdating = False

Range("B1").EntireColumn.Insert shift:=xlToRight
Range("B1").Value = "Unique Key"
x = Range("A" & Rows.Count).End(xlUp).Row
sConc = "=F2&""-""&R2&""-""&T2"
Range("B2").Resize(x - 1).Formula = sConc

Application.ScreenUpdating = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,195,934
Messages
6,012,383
Members
441,693
Latest member
TraderRick

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