ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding user defined range in macro (https://www.excelbanter.com/excel-programming/428687-adding-user-defined-range-macro.html)

Jacky D.

Adding user defined range in macro
 
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,

Jacob Skaria

Adding user defined range in macro
 
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,


Don Guillett

Adding user defined range in macro
 
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

"Jacky D." wrote in message
...
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,




All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com