PC Review


Reply
Thread Tools Rate Thread

Determine Which Columns Are Hidden with VBA

 
 
Keith
Guest
Posts: n/a
 
      7th Mar 2008
I have a spreadsheet which will be used by individuals to update an
Access database. The columns are locked, but I do allow them to hide
columns to make the data more customized. Periodically they will
refresh their data from the database. In order to avoid forcing them
to reformat to their preference (and thus encourage them to refresh
more frequently) I would like to determine which columns they have
hidden so I can unhide, update/append the new data, then hide the
columns again. The same information would be advantageous, though
less so for the autofilter properties. I have tried in vain to look
at the help files and have not found the correct text with which to
search in this group to find the answer. Thanks in advance if you
can
help.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      7th Mar 2008
You could build an array that keeps track of columnwidths:

Option Explicit
Sub testme()
Dim myColWidths() As Double
Dim MaxCols As Long
Dim iCol As Long

With Worksheets("sheet1")
MaxCols = .Columns.Count
ReDim myColWidths(1 To MaxCols)
For iCol = 1 To MaxCols
myColWidths(iCol) = .Columns(iCol).ColumnWidth
Next iCol

.Columns.Hidden = False

'do some stuff

For iCol = 1 To MaxCols
.Columns(iCol).ColumnWidth = myColWidths(iCol)
Next iCol
End With
End Sub

As for the autofilter stuff...

I saved this from a Tom Ogilvy post:
====================================

http://j-walk.com/ss/excel/usertips/tip044.htm

to get it to refresh:

=FilterCriteria(B5)&left(Subtotal(9,B5:B200),0)

this is one I wrote back in 2000

Here is a user defined function that will display the criteria in a cell:

Public Function ShowFilter(rng As Range)
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet
Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range

If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function

You could save these settings, do the work, then parse the saved settings and
reapply the criteria.

Keith wrote:
>
> I have a spreadsheet which will be used by individuals to update an
> Access database. The columns are locked, but I do allow them to hide
> columns to make the data more customized. Periodically they will
> refresh their data from the database. In order to avoid forcing them
> to reformat to their preference (and thus encourage them to refresh
> more frequently) I would like to determine which columns they have
> hidden so I can unhide, update/append the new data, then hide the
> columns again. The same information would be advantageous, though
> less so for the autofilter properties. I have tried in vain to look
> at the help files and have not found the correct text with which to
> search in this group to find the answer. Thanks in advance if you
> can
> help.


--

Dave Peterson
 
Reply With Quote
 
Keith
Guest
Posts: n/a
 
      7th Mar 2008
On Mar 7, 1:37 pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> You could build an array that keeps track of columnwidths:
>
> Option Explicit
> Sub testme()
> Dim myColWidths() As Double
> Dim MaxCols As Long
> Dim iCol As Long
>
> With Worksheets("sheet1")
> MaxCols = .Columns.Count
> ReDim myColWidths(1 To MaxCols)
> For iCol = 1 To MaxCols
> myColWidths(iCol) = .Columns(iCol).ColumnWidth
> Next iCol
>
> .Columns.Hidden = False
>
> 'do some stuff
>
> For iCol = 1 To MaxCols
> .Columns(iCol).ColumnWidth = myColWidths(iCol)
> Next iCol
> End With
> End Sub
>
> As for the autofilter stuff...
>
> I saved this from a Tom Ogilvy post:
> ====================================
>
> http://j-walk.com/ss/excel/usertips/tip044.htm
>
> to get it to refresh:
>
> =FilterCriteria(B5)&left(Subtotal(9,B5:B200),0)
>
> this is one I wrote back in 2000
>
> Here is a user defined function that will display the criteria in a cell:
>
> Public Function ShowFilter(rng As Range)
> Dim filt As Filter
> Dim sCrit1 As String
> Dim sCrit2 As String
> Dim sop As String
> Dim lngOp As Long
> Dim lngOff As Long
> Dim frng As Range
> Dim sh As Worksheet
> Set sh = rng.Parent
> If sh.FilterMode = False Then
> ShowFilter = "No Active Filter"
> Exit Function
> End If
> Set frng = sh.AutoFilter.Range
>
> If Intersect(rng.EntireColumn, frng) Is Nothing Then
> ShowFilter = CVErr(xlErrRef)
> Else
> lngOff = rng.Column - frng.Columns(1).Column + 1
> If Not sh.AutoFilter.Filters(lngOff).On Then
> ShowFilter = "No Conditions"
> Else
> Set filt = sh.AutoFilter.Filters(lngOff)
> On Error Resume Next
> sCrit1 = filt.Criteria1
> sCrit2 = filt.Criteria2
> lngOp = filt.Operator
> If lngOp = xlAnd Then
> sop = " And "
> ElseIf lngOp = xlOr Then
> sop = " or "
> Else
> sop = ""
> End If
> ShowFilter = sCrit1 & sop & sCrit2
> End If
> End If
> End Function
>
> You could save these settings, do the work, then parse the saved settings and
> reapply the criteria.
>
> Keith wrote:
>
> > I have a spreadsheet which will be used by individuals to update an
> > Access database. The columns are locked, but I do allow them to hide
> > columns to make the data more customized. Periodically they will
> > refresh their data from the database. In order to avoid forcing them
> > to reformat to their preference (and thus encourage them to refresh
> > more frequently) I would like to determine which columns they have
> > hidden so I can unhide, update/append the new data, then hide the
> > columns again. The same information would be advantageous, though
> > less so for the autofilter properties. I have tried in vain to look
> > at the help files and have not found the correct text with which to
> > search in this group to find the answer. Thanks in advance if you
> > can
> > help.

>
> --
>
> Dave Peterson


Spectacular! Works precisely as I needed- thanks again for your help.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Worksheet, Hidden Columns, .CSV Format Saves Hidden Column Da Tammy Microsoft Excel Misc 3 2nd Apr 2009 11:40 PM
Copy and Paste with hidden columns remaining hidden Pendelfin Microsoft Excel Misc 2 26th Feb 2009 11:35 AM
Determine Which Columns Are Hidden in VBA nospamkam@wowway.com Microsoft Access 1 7th Mar 2008 08:46 PM
Determine Cells(5,4) IN SPITE of hidden rows/columns Finny Microsoft Excel Programming 7 1st Mar 2007 04:01 PM
What file(s) determine whether 'hidden files' are 'hidden' or not? =?Utf-8?B?bWtyYWZ0?= Windows XP Help 6 15th Jan 2005 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.