Insert column and past from input box

Dardus

New Member
Joined
Apr 24, 2017
Messages
15
Thank you for your help. I am not getting this at the moment. I am sure I just need sleep.
Need to insert a column before E, Label it Date4, post the input provided from an inputbox in new E column (except the header):

[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Date1[/TD]
[TD]Date2[/TD]
[TD]Date3[/TD]
[TD]Code[/TD]
[TD]Value1[/TD]
[TD]Value2[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]123d[/TD]
[TD]548h548[/TD]
[TD]4/24/2017[/TD]
[/TR]
[TR]
[TD]Smith[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]542d[/TD]
[TD]879q312[/TD]
[TD]5/15/2016[/TD]
[/TR]
[TR]
[TD]Frank[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]594f[/TD]
[TD]125q632[/TD]
[TD]3/2/2016[/TD]
[/TR]
[TR]
[TD]Sam[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]668s[/TD]
[TD]978q888[/TD]
[TD]12/12/2017[/TD]
[/TR]
[TR]
[TD]Peter[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]445r[/TD]
[TD]879q688[/TD]
[TD]3/6/2008[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]684r[/TD]
[TD]558q468[/TD]
[TD]7/1/2011[/TD]
[/TR]
</tbody>[/TABLE]

To:
[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Date1[/TD]
[TD]Date2[/TD]
[TD]Date3[/TD]
[TD]Date4[/TD]
[TD]Code[/TD]
[TD]Value1[/TD]
[TD]Value2[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]Inputbox value[/TD]
[TD]123d[/TD]
[TD]548h548[/TD]
[TD]4/24/2017[/TD]
[/TR]
[TR]
[TD]Smith[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]Inputbox value[/TD]
[TD]542d[/TD]
[TD]879q312[/TD]
[TD]5/15/2016[/TD]
[/TR]
[TR]
[TD]Frank[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]Inputbox value[/TD]
[TD]594f[/TD]
[TD]125q632[/TD]
[TD]3/2/2016[/TD]
[/TR]
[TR]
[TD]Sam[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]Inputbox value[/TD]
[TD]668s[/TD]
[TD]978q888[/TD]
[TD]12/12/2017[/TD]
[/TR]
[TR]
[TD]Peter[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]Inputbox value[/TD]
[TD]445r[/TD]
[TD]879q688[/TD]
[TD]3/6/2008[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]5/1/2017[/TD]
[TD]5[/TD]
[TD]2017[/TD]
[TD]Inputbox value[/TD]
[TD]684r[/TD]
[TD]558q468[/TD]
[TD]7/1/2011[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Code:
Sub insertFill()
Dim dt As String
dt = InputBox("Enter Date", "DATE")
    If dt = "" Then Exit Sub
Columns(5).Insert
Range("E2", Cells(Rows.Count, 4).End(xlUp).Offset(, 1)) = dt
End Sub
 
Upvote 0
Thank you for the quick reply. I should have noted that the amount of rows is undetermined and can fluctuate for each time a new sheet is created. Therefore the " Range("E2", Cells(Rows.Count, 4).End(xlUp).Offset(, 1)) = dt " would not work. Is there a way to make it post the value for the number of rows for that spreadsheet and not the entire column (surpassing where the data cuts off)?
 
Upvote 0
Code:
Sub insertFill()
Dim dt As String
dt = InputBox("Enter Date", "DATE")
    If dt = "" Then Exit Sub
Columns(5).Insert
Range("E2", Cells(Rows.Count, 4).End(xlUp).Offset(, 1)) = dt
End Sub

that's strange, it seemed to work fine on my system. That syntax is for a dynamic range, not a static one. It uses column D to determine the number of rows to fill.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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