LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 493
Default Macro to Inserting Columns and then add column to horizontal total

Hi,

I have a macro that susscessfulling inserts any number of columns, however
it is SUPPOSED to keep all the formulas and clear the contents of the
inserted columns, which it does do, so that is problem number 1.

Now what i need is for the total column to be updated automatically with the
number of columns inserted. The total column has a formulae of what ever that
rows entered value is multipied by the header row value users select for that
column.

if this possibe?

here is what i have so far:
Sub InsertColAndFillFormulas(Optional vCols As Long = 0)

Dim x As Long
ActiveCell.EntireColumn.Select
If vCols = 0 Then
vCols = Application.InputBox(prompt:= _
"How many columns do you want to add?", Title:="Add Columns", _
Default:=1, Type:=1) 'Default for 1 col, type 1 is number
If vCols = False Then Exit Sub
End If

Dim sht As Worksheet, shts() As String, i As Long
ReDim shts(1 To Worksheets.Application.ActiveWorkbook. _
Windows(1).SelectedSheets.Count)
i = 0
For Each sht In _
Application.ActiveWorkbook.Windows(1).SelectedShee ts
Sheets(sht.Name).Select
i = i + 1
shts(i) = sht.Name

x = Sheets(sht.Name).UsedRange.Columns.Count 'lastcell fixup

Selection.Resize(Columnsize:=2).Columns(2).EntireC olumn. _
Resize(Columnsize:=vCols).Insert

Selection.AutoFill Selection.Resize( _
Columnsize:=vCols + 1), xlFillDefault

On Error Resume Next
Selection.Offset(1).Resize(vCols).EntireColumn. _
SpecialCells(xlConstants).ClearContents
Next sht
Worksheets(shts).Select
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running total for 2 columns IF column 3....... paulab Excel Worksheet Functions 7 November 9th 09 03:26 PM
Inserting new columns past the last column The Beverage Outlet- Cahoun GA Excel Discussion (Misc queries) 3 June 6th 08 04:56 PM
Total column changes colors when total equals sum of other columns newstacy New Users to Excel 1 April 21st 07 09:00 PM
Macro to change Chart Range when inserting a column Mark Charts and Charting in Excel 1 September 13th 05 01:12 PM
in excel just want to add 4 columns and total in next column michael_l Excel Worksheet Functions 3 April 8th 05 11:13 PM


All times are GMT +1. The time now is 10:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"