Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

I have a Sub called ColHidden() which i want to run on every workshee
in Workbook "ClearOrClosedSent.xls".
The Worksheets will have different names however.

Can anyone please tell me how to apply the Sub on all worksheets in th
afforementioned workbook?

I am using Excel 2000.

TI

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Running Macro on every sheet in Workbook !!!

Hi
try something like

sub all_sheets()
dim wks as worksheet
for each wks in worksheets
wks.column(1).hidden=true
next
end sub


--
Regards
Frank Kabel
Frankfurt, Germany


I have a Sub called ColHidden() which i want to run on every

worksheet
in Workbook "ClearOrClosedSent.xls".
The Worksheets will have different names however.

Can anyone please tell me how to apply the Sub on all worksheets in
the afforementioned workbook?

I am using Excel 2000.

TIA


---
Message posted from http://www.ExcelForum.com/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

Thanks for the reply.

Trouble is i want to Hide various columns A,F,K,L etc
and also i want to possibly add Column headings so i really want th
flexibility of just calling a Subroutine as mentioned to run on ever
sheet, but to be able to chop and change to the Subroutine itself.

Any ideas??

Thanks agai

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Running Macro on every sheet in Workbook !!!

sub all_sheets()
dim wks as worksheet
for each wks in worksheets
ChopAndChange wks
next
end sub

Sub ChopAndChange(wks as Worksheet)
wks.Columns("A:A,F:F,K:L").Hidden = True
wks.Cells(1,2).Resize(1,4).Value =Array("HeaderB", _
"HeaderC","HeaderD","HeaderE")
End sub

--
Regards,
Tom Ogilvy



"Jako " wrote in message
...
Thanks for the reply.

Trouble is i want to Hide various columns A,F,K,L etc
and also i want to possibly add Column headings so i really want the
flexibility of just calling a Subroutine as mentioned to run on every
sheet, but to be able to chop and change to the Subroutine itself.

Any ideas??

Thanks again


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

Fantastic..

Thanks again Tom

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

OOoooopps!!

Spoke to soon Tom.

wks.Columns("A:A,F:F,K:L").Hidden = True

comes up with Type mismatch error !!

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Running Macro on every sheet in Workbook !!!

Try:

wks.Range("A:A,F:F,K:L").EntireColumn.Hidden = True

--

Vasant




"Jako " wrote in message
...
OOoooopps!!

Spoke to soon Tom.

wks.Columns("A:A,F:F,K:L").Hidden = True

comes up with Type mismatch error !!!


---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Running Macro on every sheet in Workbook !!!

Try it like this:

wks.Range("A:A,F:F,K:L").EntireColumn.Hidden = True

--
Regards,
Tom Ogilvy

"Jako " wrote in message
...
OOoooopps!!

Spoke to soon Tom.

wks.Columns("A:A,F:F,K:L").Hidden = True

comes up with Type mismatch error !!!


---
Message posted from http://www.ExcelForum.com/



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

Thanks Tom but i'm a bit confused by this code:

wks.Cells(1,2).Resize(1,4).Value =Array("HeaderB", _
"HeaderC","HeaderD","HeaderE")

I have sorted the columns that i want to Hide but then i want to Inser
a column into "A" (so it is the first column on the worksheet) calle
"Heading 1" then insert from column W - Z
headings "Headig 2", "Heading 3", "Heading 4" and "Heading 5" all i
bold font.
After this i then want to make all cells on the worksheet as Tex
format.

Please advise

Many thank

--
Message posted from http://www.ExcelForum.com

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Running Macro on every sheet in Workbook !!!

wks.Columns(1).Insert
With wks.Cells(1,1)
.Value = "Heading 1"
.font.Bold = True
End With
with Range("W1").Resize(1,4)
.Value = Array( _
"Heading 2", "Heading 3", _
"Heading 4", "Heading 5")
.font.Bold = True
End With

Cells.Interior.NumberFormat = "@"

--
Regards,
Tom Ogilvy

"Jako " wrote in message
...
Thanks Tom but i'm a bit confused by this code:

wks.Cells(1,2).Resize(1,4).Value =Array("HeaderB", _
"HeaderC","HeaderD","HeaderE")

I have sorted the columns that i want to Hide but then i want to Insert
a column into "A" (so it is the first column on the worksheet) called
"Heading 1" then insert from column W - Z
headings "Headig 2", "Heading 3", "Heading 4" and "Heading 5" all in
bold font.
After this i then want to make all cells on the worksheet as Text
format.

Please advise

Many thanks


---
Message posted from http://www.ExcelForum.com/





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

Tom,
Thanks again but only the first worksheet is formatted as i need.
Here is the code i now have:



Sub all_sheets()
Dim wks As Worksheet
For Each wks In Worksheets
ChopAndChange wks
Next
End Sub

Sub ChopAndChange(wks As Worksheet)
wks.Range("C:C,G:G,I:I,K:M,P:R").EntireColumn.Hidd en = True
wks.Columns(1).Insert
With wks.Cells(1, 1)
.Value = "Heading 1"
.Font.Bold = True
End With
With Range("W1").Resize(1, 4)
.Value = Array( _
"Heading 2", "Heading 3", _
"Heading 4", "Heading 5")
.Font.Bold = True
End With


Sheets 2 & 3 have the 1st columns + "Heading 1" but not the
W - Z column changes.

TI

--
Message posted from http://www.ExcelForum.com

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

Jako,

Not realy sure, but change:

For Each wks In Worksheets

to

For Each wks In Workbook

HTH

Charle

--
Message posted from http://www.ExcelForum.com

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Running Macro on every sheet in Workbook !!!

Thanks Charles but that comes up with an error !!

I have come up with this code that does exactly what i want but i
anyone can optimise it i would be most grateful.



Sub all_sheets()
Dim wks As Worksheet
For Each wks In Worksheets
'For Each wks In Workbook
ChopAndChange wks
Next
End Sub

Sub ChopAndChange(wks As Worksheet)
wks.Range("C:C,G:G,I:I,K:M,P:R").EntireColumn.Hidd en = True
wks.Columns(1).Insert
With wks.Cells(1, 1)
.Value = "Heading 1"
.Font.Bold = True
End With
With wks.Cells(1, 23)
.Value = "Heading 2"
.Font.Bold = True
End With
With wks.Cells(1, 24)
.Value = "Heading 3"
.Font.Bold = True
End With
With wks.Cells(1, 25)
.Value = "Heading 4"
.Font.Bold = True
End With
With wks.Cells(1, 26)
.Value = "Heading 5"
.Font.Bold = True
End With

Many thanks to all

--
Message posted from http://www.ExcelForum.com

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Running Macro on every sheet in Workbook !!!

I think that this'll work for you:

Option Explicit

Sub all_sheets()
Dim wks As Worksheet
For Each wks In Worksheets
ChopAndChange wks
Next
End Sub

Sub ChopAndChange(wks As Worksheet)
wks.Range("C:C,G:G,I:I,K:M,P:R").EntireColumn.Hidd en = True
wks.Columns(1).Insert
With wks.Cells(1, 1)
.Value = "Heading 1"
.Font.Bold = True
End With
With wks.Range("W1").Resize(1, 4)
.Value = Array( _
"Heading 2", "Heading 3", _
"Heading 4", "Heading 5")
.Font.Bold = True
End With
End Sub

I changed this line:
With Range("W1").Resize(1, 4)
to
With wks.Range("W1").Resize(1, 4)



"Jako <" wrote:

Tom,
Thanks again but only the first worksheet is formatted as i need.
Here is the code i now have:

Sub all_sheets()
Dim wks As Worksheet
For Each wks In Worksheets
ChopAndChange wks
Next
End Sub

Sub ChopAndChange(wks As Worksheet)
wks.Range("C:C,G:G,I:I,K:M,P:R").EntireColumn.Hidd en = True
wks.Columns(1).Insert
With wks.Cells(1, 1)
Value = "Heading 1"
Font.Bold = True
End With
With Range("W1").Resize(1, 4)
Value = Array( _
"Heading 2", "Heading 3", _
"Heading 4", "Heading 5")
Font.Bold = True
End With

Sheets 2 & 3 have the 1st columns + "Heading 1" but not the
W - Z column changes.

TIA

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Running Macro on every sheet in Workbook !!!

wks.Columns(1).Insert
With wks.Cells(1,1)
.Value = "Heading 1"
.font.Bold = True
End With
with wks.Range("W1").Resize(1,4)
.Value = Array( _
"Heading 2", "Heading 3", _
"Heading 4", "Heading 5")
.font.Bold = True
End With

wks.Cells.Interior.NumberFormat = "@"


--
Regards,
Tom Ogilvy


"Jako " wrote in message
...
Tom,
Thanks again but only the first worksheet is formatted as i need.
Here is the code i now have:



Sub all_sheets()
Dim wks As Worksheet
For Each wks In Worksheets
ChopAndChange wks
Next
End Sub

Sub ChopAndChange(wks As Worksheet)
wks.Range("C:C,G:G,I:I,K:M,P:R").EntireColumn.Hidd en = True
wks.Columns(1).Insert
With wks.Cells(1, 1)
Value = "Heading 1"
Font.Bold = True
End With
With Range("W1").Resize(1, 4)
Value = Array( _
"Heading 2", "Heading 3", _
"Heading 4", "Heading 5")
Font.Bold = True
End With


Sheets 2 & 3 have the 1st columns + "Heading 1" but not the
W - Z column changes.

TIA


---
Message posted from http://www.ExcelForum.com/



Reply
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 macro in another workbook Barb Reinhardt Excel Worksheet Functions 1 April 25th 07 08:30 PM
Help:Running a macro in one excel workbook from another workbook R Kapoor Setting up and Configuration of Excel 3 January 13th 06 05:11 AM
Running a macro in another workbook Blue Excel Programming 1 July 10th 04 04:04 PM
Running a macro in another workbook Blue Excel Programming 4 July 9th 04 07:38 PM
Running Code on Each Sheet in an Excel Workbook bearie Excel Programming 2 February 6th 04 03:54 PM


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

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

About Us

"It's about Microsoft Excel"