PDA

View Full Version : VBA To Insert Specific Column Before Every Existing Columns



CORAL
03-17-2014, 03:04 PM
hi i have many columns up to 500 and i want to insert one column that is spesified time before every colunmns with vb the column is as below 00:00 00:30 . . . . . 23:00 23:30 00:00

Rick Rothstein
03-17-2014, 09:06 PM
hi i have many columns up to 500 and i want to insert one column that is spesified time before every colunmns with vb the column is as below 00:00 00:30 . . . . . 23:00 23:30 00:00
Does this macro do what you want?

Sub InsertRowBefore()
Dim X As Long, Col As String
Col = Application.InputBox("Enter time to insert at...", Type:=2)
For X = 100 To 1 Step -1
If Cells(1, X).Text = Col Then Columns(X).Insert
Next
End Sub

CORAL
03-19-2014, 11:52 AM
maybe i cant explain well and possible that i cant use the code properly please help me i want to insert one spesified column before every column(up to 400)
this column is
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30
00:00

Rick Rothstein
03-24-2014, 07:00 PM
I am apparently having trouble figuring out your layout and what you want to do with it. Can you create a sample workbook where on Sheet1 you show existing data similar to what you actually have as real data and then on Sheet2 you copy that exact data and then insert the columns you want inserted and then attach a copy of that workbook to your response so that we can see exactly what you are trying to describe to us?

CORAL
04-03-2014, 08:18 PM
i cant attach and i dont know why

Excel Fox
04-03-2014, 09:18 PM
If the file size is more than limit, try saving it to a file share site, and post the link here.

CORAL
04-04-2014, 08:45 AM
i shared the excel file here a - Download - 4shared - marjan mashayekhpour (http://www.4shared.com/file/Ehuoarfkce/a_online.html)
with best regard

snb
04-04-2014, 03:16 PM
You can't add columns to a worksheet: it always contains 16384 columns.
You can move data in the worksheet though:


Sub M_snb()
sheets("sheet1").usedrange.cut sheets("sheet1").cells(1,2)
End sub