ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert column macro (https://www.excelbanter.com/excel-programming/361729-insert-column-macro.html)

Altec101

insert column macro
 

Hello,

Does anyone know how to have a macro in Excell insert a new colum
automatically?

Also, if i was comparing dates in two columns, how could i have i
automatically enter the difference in the column newly created?

Thanks,

Chri

--
Altec10
-----------------------------------------------------------------------
Altec101's Profile: http://www.excelforum.com/member.php...fo&userid=3453
View this thread: http://www.excelforum.com/showthread.php?threadid=54300


Ikaabod[_75_]

insert column macro
 

Yes, you can insert a column automatically and have it enter th
difference b/t two dates. What events will trigger the macro to inser
a column and enter the difference?
Altec101 Wrote:
Hello,

Does anyone know how to have a macro in Excell insert a new colum
automatically?

Also, if i was comparing dates in two columns, how could i have i
automatically enter the difference in the column newly created?

Thanks,

Chri


--
Ikaabo
-----------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...fo&userid=3337
View this thread: http://www.excelforum.com/showthread.php?threadid=54300


Altec101[_2_]

insert column macro
 

I would like to have it insert the column and data when the macro is run
manually.


--
Altec101
------------------------------------------------------------------------
Altec101's Profile: http://www.excelforum.com/member.php...o&userid=34539
View this thread: http://www.excelforum.com/showthread...hreadid=543007


Ikaabod[_77_]

insert column macro
 

Here's an example of how you might go about it, tho obviously your
ranges will likely differ:
Sub MyMacro()
Range("C:C").EntireColumn.Insert
With Range("C1")
..Value = "=(B1-A1)"
..NumberFormat = "General"
End With
End Sub

Then you can create a macro button to Call MyMacro when pressed.
Altec101 Wrote:
I would like to have it insert the column and data when the macro is run
manually.



--
Ikaabod
------------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
View this thread: http://www.excelforum.com/showthread...hreadid=543007


Altec101[_3_]

insert column macro
 

Thanks for the reply.

If i had 2 columns of data with multiple rows (say 50 rows - the amount
of rows will be different each time) and wanted to get a date difference
between column C and D and have it automatically input the difference
into column E, is there a way I can do that ?


--
Altec101
------------------------------------------------------------------------
Altec101's Profile: http://www.excelforum.com/member.php...o&userid=34539
View this thread: http://www.excelforum.com/showthread...hreadid=543007


Ikaabod[_78_]

insert column macro
 

Give this a go
Sub MyMacro()
Dim i As Integer
i = 0
Range("E:E").EntireColumn.Insert
Range("E1").Select
Do
If IsEmpty(ActiveCell.Offset(i, -1)) = False Then
ActiveCell.Offset(i, 0).Value = "=(D1-C1)"
i = i + 1
End If
Loop Until IsEmpty(ActiveCell.Offset(i, -1))
Range("E:E").NumberFormat = "General"
End Sub
Altec101 Wrote:
Thanks for the reply.

If i had 2 columns of data with multiple rows (say 50 rows - the amount
of rows will be different each time) and wanted to get a date difference
between column C and D and have it automatically input the difference
into column E, is there a way I can do that ?



--
Ikaabod
------------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
View this thread: http://www.excelforum.com/showthread...hreadid=543007


Ikaabod[_79_]

insert column macro
 

Let's try this then...
Sub MyMacro()
Dim i As Integer
i = 0
Range("E:E").EntireColumn.Insert
Range("E1").Select
Do
If IsEmpty(ActiveCell.Offset(i, -1)) = False Then
ActiveCell.Offset(i, 0).FormulaR1C1 = "=(rc[-1]-rC[-2])"
i = i + 1
End If
Loop Until IsEmpty(ActiveCell.Offset(i, -1))
Range("E:E").NumberFormat = "General"
End Sub
Altec101 Wrote:
Thanks for the reply.

If i had 2 columns of data with multiple rows (say 50 rows - the amount
of rows will be different each time) and wanted to get a date difference
between column C and D and have it automatically input the difference
into column E, is there a way I can do that ?



--
Ikaabod
------------------------------------------------------------------------
Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
View this thread: http://www.excelforum.com/showthread...hreadid=543007


Altec101[_4_]

insert column macro
 

Thanks for the help


--
Altec101
------------------------------------------------------------------------
Altec101's Profile: http://www.excelforum.com/member.php...o&userid=34539
View this thread: http://www.excelforum.com/showthread...hreadid=543007



All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com