Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Hide Columns

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Hide Columns

Dear Shakeel

Try the below and feedback...

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 1 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Hide Columns

Dear Jacob Skaria

your code is almost work for me but I think I should alter my question more,
if I want this condition to be applied on some specific cells (e.g. column A
B C) so what would be the code in this situation
--
Regards,



"Jacob Skaria" wrote:

Dear Shakeel

Try the below and feedback...

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 1 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Hide Columns

Dear Shakeel

Instead of

lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column


you can directly mention it as 3 if you want this to run only for A,B,C
(last column 3)

lngLastCol = 3

If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Dear Jacob Skaria

your code is almost work for me but I think I should alter my question more,
if I want this condition to be applied on some specific cells (e.g. column A
B C) so what would be the code in this situation
--
Regards,



"Jacob Skaria" wrote:

Dear Shakeel

Try the below and feedback...

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 1 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Hide Columns

Dear Jacob Skaria

Sorry for bothering you, if write lngcol = 3 its work perfectly but what if
I want macro to run on column BCD only.

--
Regards,



"Jacob Skaria" wrote:

Dear Shakeel

Instead of

lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column


you can directly mention it as 3 if you want this to run only for A,B,C
(last column 3)

lngLastCol = 3

If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Dear Jacob Skaria

your code is almost work for me but I think I should alter my question more,
if I want this condition to be applied on some specific cells (e.g. column A
B C) so what would be the code in this situation
--
Regards,



"Jacob Skaria" wrote:

Dear Shakeel

Try the below and feedback...

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 1 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Hide Columns

Change lngCol from 1 to 2 as below

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = 4
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 2 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Dear Jacob Skaria

Sorry for bothering you, if write lngcol = 3 its work perfectly but what if
I want macro to run on column BCD only.

--
Regards,



"Jacob Skaria" wrote:

Dear Shakeel

Instead of

lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column


you can directly mention it as 3 if you want this to run only for A,B,C
(last column 3)

lngLastCol = 3

If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Dear Jacob Skaria

your code is almost work for me but I think I should alter my question more,
if I want this condition to be applied on some specific cells (e.g. column A
B C) so what would be the code in this situation
--
Regards,



"Jacob Skaria" wrote:

Dear Shakeel

Try the below and feedback...

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 1 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Hide Columns

Hi Jacob,

This is something that I would like to use, but I would like it to ignore
the first row. And, I need it for all sheets in the workbook. Are you able
to help me with this?
--
Thank you, Jodie


"Jacob Skaria" wrote:

Dear Shakeel

Try the below and feedback...

Sub HideBlankColumns()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
lngLastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
lngLastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("A1", Cells(1, lngLastCol)).Columns.Hidden = False
For lngCol = 1 To lngLastCol
If WorksheetFunction.CountBlank(Range(Cells(1, lngCol), _
Cells(lngLastRow, lngCol))) = lngLastRow Then
Columns(lngCol).Hidden = True
End If
Next
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Abdul Shakeel" wrote:

Hi All,



I am searching for macro that hide or delete column(s) if they havent any
values, & if any cell in that particular column(s) have any value then we
couldnt delete or hide the column.



Regards,



Shakeel

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Hide Columns

Think about another plan.

You cannot hide part of a column.


Gord Dibben MS Excel MVP

On Fri, 30 Oct 2009 06:34:01 -0700, Jodie
wrote:

Hi Jacob,

This is something that I would like to use, but I would like it to ignore
the first row. And, I need it for all sheets in the workbook. Are you able
to help me with this?


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Hide Columns

Thank you Gord, for your input. However, I am not looking to hide part of a
column. What I am referring to is to ignore the first row when determining
if the column is blank or equals zero. If everything is blank or equals zero
after the first row, then hide the entire column.
--
Thank you, Jodie


"Gord Dibben" wrote:

Think about another plan.

You cannot hide part of a column.


Gord Dibben MS Excel MVP

On Fri, 30 Oct 2009 06:34:01 -0700, Jodie
wrote:

Hi Jacob,

This is something that I would like to use, but I would like it to ignore
the first row. And, I need it for all sheets in the workbook. Are you able
to help me with this?


.

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
Want to Hide columns in spreadsheet but NOT hide data in chart. KrispyData Charts and Charting in Excel 1 March 20th 09 04:45 PM
Hide/Unhide columns using button on top over relevant columns [email protected] Excel Discussion (Misc queries) 1 March 7th 07 09:24 PM
I set up a macro to hide/unhide columns. It hides more columns Lori Excel Programming 1 September 6th 06 04:08 PM
Hide columns alm09 Excel Discussion (Misc queries) 1 June 27th 05 04:14 PM
Excel button :: Filter columns by value - possible? Additionally, hide certain columns No Name Excel Programming 4 December 28th 04 07:44 PM


All times are GMT +1. The time now is 06:30 AM.

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"