VBA adding column then adding Left formula

pkam2010

New Member
Joined
Mar 29, 2019
Messages
19
HI

am new to VBA and trying to create a Marco to add columns to E and L, which i have a as

Range("E1").EntireColumn.Insert
Range("L1").EntireColumn.Insert

but then i want to add a formula to E and L of =Left(D5,5) and =left(k5,5) going down to the last row. but if in row 6 it will be D6 and K6 etc. so the fomula changes as to what row it is in.
the data set i am look at start in row 5


thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Re: Help with VBA adding column then adding Left formula

How about
Code:
Sub pkam2010()
   Dim Lr As Long
   
   Lr = Range("A" & Rows.Count).End(xlUp).Row
   Range("E:E,K:K").EntireColumn.Insert
   Range("E5:E" & Lr & ",L5:L" & Lr).FormulaR1C1 = "=left(rc[-1],5)"
End Sub
 
Upvote 0
Re: Help with VBA adding column then adding Left formula

You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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