Esconder Columnas y Renglones en donde el valor sea "0" en un rango especifico

lalo001

New Member
Joined
Jul 30, 2013
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hola espero me puedan ayudar,

Estoy tratando de encontrar un codigo en donde puedueda esconder las columnas y renglones dentro de un rango especificado.

tengo un reporte que va del rango "A3" a "AB164" como puedo esconder las columnas y renglones en donde no haya ningun valor en toda la coluimna o renglon?

Gracias de antemano por su ayuda.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Algo asi:

Sub test()
Dim rstart As Range
Dim rend As Range
Dim i As Integer
Dim rcell As Range
Dim rtest As Range
Dim lcol As Long


'para las columnas
For lcol = 0 To 28 Step 1
Set rcell = Range("a1").Offset(0, lcol)
If Len(rcell.Value) = 0 Then
Set rtest = rcell.End(xlDown)
If rtest.Row = Rows.Count And Len(rtest.Value) = 0 Then
Columns(rcell.Column).Hidden = True
End If
End If
Next

'para los renglones
Set rstart = Range("a1")
Set rend = Range("a164").Offset(0, 27)
Range(rstart, rend).Select

For i = 1 To Selection.Rows.Count
If WorksheetFunction.CountBlank(Selection.Rows(i)) = 28 Then
Selection.Rows(i).EntireRow.Hidden = True
End If
Next i

End Sub

El codigo es una capirotada de varios post que me piratie.

Saludos,

Benjamin
 
Upvote 0
Benjamin,

Muchas gracias por la ayuda el codigo funciona perfecto para esconder los renglones, pero no esconde las columnas, alguna otra sugerencia?
 
Upvote 0
<font face=Consolas, "Lucida Sans Typewriter", "Lucida Console", "Courier New", Monospace><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><SPAN style="color:#007F00">'// -----------------------------------------------------------------</SPAN><br><SPAN style="color:#007F00">'// escrito por Greg Truby</SPAN><br><SPAN style="color:#007F00">'// escrito para lalo001</SPAN><br><br><SPAN style="color:#007F00">'// resumen - lalo001 quiere esconder todas las columnas y ringlones</SPAN><br><SPAN style="color:#007F00">'// que estén completamente vacias dentro de un rango dado.</SPAN><br><SPAN style="color:#007F00">'// -----------------------------------------------------------------</SPAN><br><br><SPAN style="color:#007F00">'// ponga el valor de TRUE para este constante si quiere ver detalles</SPAN><br><SPAN style="color:#007F00">'// de la operacion en la ventana de observación.</SPAN><br><SPAN style="color:#00007F">Const</SPAN> mc_booDebugMode <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN> = <SPAN style="color:#00007F">False</SPAN><br><br><br><SPAN style="color:#007F00">'// cambie la dirección de las celdas aquí.  O mejor</SPAN><br><SPAN style="color:#007F00">'// use un rango nombrado y ponga el nombre del rango</SPAN><br><SPAN style="color:#007F00">'// aquí.</SPAN><br><SPAN style="color:#00007F">Const</SPAN> mc_strAddressToReview  <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> = "A3:AB164"<br><br><br><SPAN style="color:#00007F">Sub</SPAN> EsconderVacios()<br>    <br>    <SPAN style="color:#00007F">Dim</SPAN> lngCounter      <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>        rngReviewCol    <SPAN style="color:#00007F">As</SPAN> Excel.Range, _<br>        rngReviewRow    <SPAN style="color:#00007F">As</SPAN> Excel.Range, _<br>        rngToReview     <SPAN style="color:#00007F">As</SPAN> Excel.Range, _<br>        wf              <SPAN style="color:#00007F">As</SPAN> Excel.WorksheetFunction<br><br>    <SPAN style="color:#007F00">'// note que no se use la palabra NEW, es solo un SET</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> wf = Application.WorksheetFunction<br>    <br>    <SPAN style="color:#007F00">'// vamos a suponer que se trata de la hoja activa</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> rngToReview = Range(mc_strAddressToReview)<br>    <SPAN style="color:#00007F">If</SPAN> mc_booDebugMode <SPAN style="color:#00007F">Then</SPAN> Debug.Print "Using Sheet: " & rng<SPAN style="color:#00007F">To</SPAN>Review.Parent.Name<br>    <br>    <SPAN style="color:#007F00">'// ----------------------------------------------------------------</SPAN><br>    <SPAN style="color:#007F00">'// realmente sería posible no usar unas variables como</SPAN><br>    <SPAN style="color:#007F00">'// rngReviewCol o rngReviewRow. Pero usarlas hace el proceso de</SPAN><br>    <SPAN style="color:#007F00">'// "matar bichos" (debugging) más fácil.</SPAN><br>    <SPAN style="color:#007F00">'// ----------------------------------------------------------------</SPAN><br>    <br>   <br>    <SPAN style="color:#007F00">'// buscamos ringlones vacios</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> lngCounter = 1 To rngToReview.Rows.Count<br>    <br>        <SPAN style="color:#00007F">Set</SPAN> rngReviewRow = rng<SPAN style="color:#00007F">To</SPAN>Review.Rows(lngCounter)<br>        <br>        <SPAN style="color:#00007F">If</SPAN> mc_booDebugMode <SPAN style="color:#00007F">Then</SPAN> Debug.Print rngReviewRow.Address(0, 0), "|", wf.CountA(rngReviewRow)<br>        <br>        rngReviewRow.EntireRow.Hidden = (wf.CountA(rngReviewRow) = 0)<br>    <br>    <SPAN style="color:#00007F">Next</SPAN> lngCounter<br>    <br>    <SPAN style="color:#007F00">'// ahora revisamos las columnas</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> lngCounter = 1 To rngToReview.Columns.Count<br>    <br>        <SPAN style="color:#00007F">Set</SPAN> rngReviewCol = rngToReview.Columns(lngCounter)<br>        <br>        <SPAN style="color:#00007F">If</SPAN> mc_booDebugMode <SPAN style="color:#00007F">Then</SPAN> Debug.Print rngReviewCol.Address(0, 0), "|", wf.CountA(rngReviewCol)<br>        <br>        rngReviewCol.EntireColumn.Hidden = (wf.CountA(rngReviewCol) = 0)<br>    <br>    <SPAN style="color:#00007F">Next</SPAN> lngCounter<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> ShowAllWithinRange()<br>    <SPAN style="color:#00007F">With</SPAN> Range(mc_strAddressToReview)<br>        .EntireColumn.Hidden = <SPAN style="color:#00007F">False</SPAN><br>        .EntireRow.Hidden = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> With<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Greg, Funciona perfecto, de verdad muchas gracias por la ayuda!!!!:)
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,569
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top