PC Review


Reply
Thread Tools Rate Thread

Adding user defined range in macro

 
 
Jacky D.
Guest
Posts: n/a
 
      19th May 2009
I'd like to know if I can add an inputbox to the following macro so I can
define what row to test the If statement against. Right now, I am going into
the macro and changing the range (ie from "A31:CL31" to "A50:CL50"), but
that's un ugly solution. I am not a programmer, and am usually pretty good at
finding code and modifying to suit my needs, but this is a bit beyond my
scope.

Macro to hide rows if column is zero:

Sub Clear_Empty_Columns()
'
' Clear_Empty_Columns Macro
' Macro recorded 5/19/2009 by Jacky Del Hoyo
'

'
For Each cell In Range("A31:CL31").Cells
If (cell) = 0 Then
cell.Columns.EntireColumn.Hidden = True
Else
cell.Columns.EntireColumn.Hidden = False
End If
Next cell

End Sub
Thanks,
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      19th May 2009
Sub Clear_Empty_Columns()
' Clear_Empty_Columns Macro
' Macro recorded 5/19/2009 by Jacky Del Hoyo
'
Dim varRange As Range
Set varRange = Application.InputBox("Select range", Type:=8)

For Each cell In varRange.Cells
If (cell) = 0 Then
cell.Columns.EntireColumn.Hidden = True
Else
cell.Columns.EntireColumn.Hidden = False
End If
Next cell

End Sub

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


"Jacky D." wrote:

> I'd like to know if I can add an inputbox to the following macro so I can
> define what row to test the If statement against. Right now, I am going into
> the macro and changing the range (ie from "A31:CL31" to "A50:CL50"), but
> that's un ugly solution. I am not a programmer, and am usually pretty good at
> finding code and modifying to suit my needs, but this is a bit beyond my
> scope.
>
> Macro to hide rows if column is zero:
>
> Sub Clear_Empty_Columns()
> '
> ' Clear_Empty_Columns Macro
> ' Macro recorded 5/19/2009 by Jacky Del Hoyo
> '
>
> '
> For Each cell In Range("A31:CL31").Cells
> If (cell) = 0 Then
> cell.Columns.EntireColumn.Hidden = True
> Else
> cell.Columns.EntireColumn.Hidden = False
> End If
> Next cell
>
> End Sub
> Thanks,

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      19th May 2009
Should do it

Sub hidecolumnsinrow()
mycell = InputBox("Enter starting cell ie: a20")
mr = Range(mycell).Row
mc = Range(mycell).Column
lc = Cells(mr, Columns.Count).End(xlToLeft).Column
For i = mc To lc
If Cells(mr, i) = 0 Then Columns(i).Hidden = True
Next i
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Jacky D." <(E-Mail Removed)> wrote in message
news:C54DDF62-887D-4A7B-9744-(E-Mail Removed)...
> I'd like to know if I can add an inputbox to the following macro so I can
> define what row to test the If statement against. Right now, I am going
> into
> the macro and changing the range (ie from "A31:CL31" to "A50:CL50"), but
> that's un ugly solution. I am not a programmer, and am usually pretty good
> at
> finding code and modifying to suit my needs, but this is a bit beyond my
> scope.
>
> Macro to hide rows if column is zero:
>
> Sub Clear_Empty_Columns()
> '
> ' Clear_Empty_Columns Macro
> ' Macro recorded 5/19/2009 by Jacky Del Hoyo
> '
>
> '
> For Each cell In Range("A31:CL31").Cells
> If (cell) = 0 Then
> cell.Columns.EntireColumn.Hidden = True
> Else
> cell.Columns.EntireColumn.Hidden = False
> End If
> Next cell
>
> End Sub
> Thanks,


 
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
User Defined Range caveman.savant Microsoft Excel Programming 3 13th Feb 2009 02:59 PM
Rename Several Defined Range Names with Macro ExcelUser777 Microsoft Excel Programming 2 2nd Jan 2007 01:51 PM
User defined print range cebubum via AccessMonster.com Microsoft Access Reports 2 11th Sep 2006 11:39 AM
User defined date range =?Utf-8?B?VGVyaQ==?= Microsoft Access Getting Started 14 25th Apr 2006 08:43 PM
How to: User Form to assign a user defined range to a macro variab =?Utf-8?B?VHJldlRyYXY=?= Microsoft Excel Programming 1 22nd Mar 2005 07:57 PM


Features
 

Advertising
 

Newsgroups
 


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