Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Macro has stopped working!!!

Remove the single apostrophe from in front of each line of code.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"PG Oriel"
wrote in message
Hi, I have the following code which is meant to hide columns where there is
no data in certain columns. It used to auto update but it stopped working so
I tried attaching it to a button but it too has stopped working. Any idea
why? The system works by have pupils names in column B, class in column C and
levels of behaviour on column C onwards, starting in row B for my first set.
I want it to autofilter and then hide columns where there is no information
for any column from C onwards for a class. eg. Column D and Column F might
be empty for Class 7P which occupy rows 37-65 etc.

-snip-

'Private Sub Worksheet_Calculate()
'If Me.AutoFilterMode Then
'ABC
'Else
'Columns.Hidden = False
'End If
'End Sub

'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'If Me.AutoFilterMode Then
'ABC
'Else
'Columns.Hidden = False
'End If
'End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Macro has stopped working!!!

I added a three message boxes to your code.
Run it and see if you can reconcile what they tell you with
what you see or are expecting...
'-------------
Sub ABC()
Dim lastColumn As Long, rngA As Range, i As Long
Dim rng1 As Range
'Application.ScreenUpdating = False
Columns.Hidden = False
lastColumn = Me.Cells(2, "IV").End(xlToLeft).Column
Set rngA = Me.AutoFilter.Range
Set rngA = rngA.Offset(1, 0).Resize(rngA.Rows.Count - 1, 1)
MsgBox "AutoFilter range is " & rngA.Address
For i = 4 To lastColumn
Set rng1 = Cells(2, i).Resize(rngA.Rows.Count, 1)
MsgBox "Checking totals for range " & rng1.Address
If Application.Subtotal(2, rng1) = 0 Then
MsgBox rng1.Address & " has no total and wiil be hidden. "
Columns(i).Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html




"PG Oriel"
wrote in message
Hi, I have done this, saved it and restarted the xls sheet and it still
doesn't work. It seems to work up to column X Y and Z which aren't hiding,
despite being blank and there being information in column AA.

"Jim Cone" wrote:
Remove the single apostrophe from in front of each line of code.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"PG Oriel"
wrote in message
Hi, I have the following code which is meant to hide columns where there is
no data in certain columns. It used to auto update but it stopped working so
I tried attaching it to a button but it too has stopped working. Any idea
why? The system works by have pupils names in column B, class in column C and
levels of behaviour on column C onwards, starting in row B for my first set.
I want it to autofilter and then hide columns where there is no information
for any column from C onwards for a class. eg. Column D and Column F might
be empty for Class 7P which occupy rows 37-65 etc.

-snip-

'Private Sub Worksheet_Calculate()
'If Me.AutoFilterMode Then
'ABC
'Else
'Columns.Hidden = False
'End If
'End Sub

'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'If Me.AutoFilterMode Then
'ABC
'Else
'Columns.Hidden = False
'End If
'End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Macro has stopped working!!!

Hi Jim,

It was working a treat and I could see it hiding the columns. It then got to
column X and stopped. Therefore columns Y, Z, and AA which also need hiding
haven't been hidden. If you know why the help is greatly appreciated.

Thanks.
Paul

"Jim Cone" wrote:

I added a three message boxes to your code.
Run it and see if you can reconcile what they tell you with
what you see or are expecting...
'-------------
Sub ABC()
Dim lastColumn As Long, rngA As Range, i As Long
Dim rng1 As Range
'Application.ScreenUpdating = False
Columns.Hidden = False
lastColumn = Me.Cells(2, "IV").End(xlToLeft).Column
Set rngA = Me.AutoFilter.Range
Set rngA = rngA.Offset(1, 0).Resize(rngA.Rows.Count - 1, 1)
MsgBox "AutoFilter range is " & rngA.Address
For i = 4 To lastColumn
Set rng1 = Cells(2, i).Resize(rngA.Rows.Count, 1)
MsgBox "Checking totals for range " & rng1.Address
If Application.Subtotal(2, rng1) = 0 Then
MsgBox rng1.Address & " has no total and wiil be hidden. "
Columns(i).Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html




"PG Oriel"
wrote in message
Hi, I have done this, saved it and restarted the xls sheet and it still
doesn't work. It seems to work up to column X Y and Z which aren't hiding,
despite being blank and there being information in column AA.

"Jim Cone" wrote:
Remove the single apostrophe from in front of each line of code.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"PG Oriel"
wrote in message
Hi, I have the following code which is meant to hide columns where there is
no data in certain columns. It used to auto update but it stopped working so
I tried attaching it to a button but it too has stopped working. Any idea
why? The system works by have pupils names in column B, class in column C and
levels of behaviour on column C onwards, starting in row B for my first set.
I want it to autofilter and then hide columns where there is no information
for any column from C onwards for a class. eg. Column D and Column F might
be empty for Class 7P which occupy rows 37-65 etc.

-snip-

'Private Sub Worksheet_Calculate()
'If Me.AutoFilterMode Then
'ABC
'Else
'Columns.Hidden = False
'End If
'End Sub

'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'If Me.AutoFilterMode Then
'ABC
'Else
'Columns.Hidden = False
'End If
'End Sub



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
Spreadsheet macro stopped working! Anders[_2_] Excel Discussion (Misc queries) 5 November 22nd 09 05:28 PM
Macro stopped working Ed Davis[_2_] Excel Discussion (Misc queries) 5 October 7th 09 11:46 PM
macro stopped working after upgrade to 2007 mohavv Excel Discussion (Misc queries) 1 June 16th 09 01:38 AM
why did the macro stopped working? Martyn Excel Programming 12 April 21st 04 03:29 PM
HELP! Button/Macro or Function has stopped working! ikcizokm Excel Programming 3 September 6th 03 08:51 PM


All times are GMT +1. The time now is 01:57 AM.

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"