VBA to insert column and write concatenation formula

nirvehex

Well-known Member
Joined
Jul 27, 2011
Messages
505
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
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,222,396
Messages
6,165,759
Members
451,985
Latest member
jchunowitz

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