| | #51 (permalink) | ||
| Slaying Bad Memes | Re: Pyro's Excel Goodies Quote:
The solution involves doing three things: 1. Define range names to store the widths of your hide-able columns. 2. Create HIDE and REVEAL macros. 3. Create HIDE and REVEAL buttons. 1. I am assuming you want to hide one or more entire columns. Let us assume you want to hide columns B, C and D. Somewhere on that same page of your spreadsheet, out of the way of all your data, build a small table with the following Range-Names: ColBwid ColCwid ColDwid Our little table will (in this case) be three rows long, and exactly two columns wide. The cells to the right of our three names should be blank and unused. Select all cells containing our Range-Names --AND-- the blank cells to their right. In my case, I am selecting 6 cells. Pull down menu:Insert:Name:Create, and make sure the box "Left" is selected. Click OKAY. You have now created 3 Range-Names in your spreadsheet. This is where the HIDE macro will store the current sizes of your columns. 2. Pull down menu:Tools:Macro:Visual Basic Editor. The Project Window should be on the left. In there you will see the name of your spreadsheet. Under that is a folder for "Objects" and a folder for "Modules". Open the latter. If there is no Module, then pull down menu:Insert:Module. The blank module will appear on the right. In the module type (or copy and paste) your two Macros: Code: Sub Hider()
Range("B:B").Select
Range("ColBwid").Value = Selection.ColumnWidth
Range("C:C").Select
Range("ColCwid").Value = Selection.ColumnWidth
Range("D:D").Select
Range("ColDwid").Value = Selection.ColumnWidth
Columns("B:D").Select
Selection.ColumnWidth = 0 'Hide the columns!
End Sub
Sub Revealer()
'Restore the columns!
Range("B:B").Select
Selection.ColumnWidth = Range("ColBwid").Value
Range("C:C").Select
Selection.ColumnWidth = Range("ColCwid").Value
Range("D:D").Select
Selection.ColumnWidth = Range("ColDwid").Value
End Sub
Click the button icon on the Forms toolbar. With your "cross" cursor draw your first button in a 4-cell block. Repeat for your second button. If you Right_Click either button, it will allow you to change it, resize it, move it, select and retype its name, assign its macro. Change the names to HIDE and REVEAL. Click some cell away from the buttons so they're not selected. Again, Right_Click each button in turn and select "Assign Macro". Pick the corresponding macro for each button. Click some cell away from the buttons so they're not selected. That's All, Folks! Make sure you click the HIDE button first so the Range-Names will be initialized. The REVEAL button will re-expand the columns to the same width they were before. I thought you would like that. ![]() ---------------- Hypography Forums Moderator -- - - - - - What concerns me is not the way things are, but rather the way people think things are. Epictetus, Greek Philosopher The map is NOT the territory. Korzybski, Polish-American Philosopher Last edited by Pyrotex; 07-09-2008 at 11:24 AM. Reason: Clarity | ||
| |||
| | #52 (permalink) | |
| Resident USSRian | Re: Pyro's Excel Goodies I do, all props to the king of macros ![]() All hail Pyro ![]() ![]() ![]() ---------------- And remember that great question that Pierre-Simon Laplace and Sir Isaac Newton, Andrei Markov and David Hilbert, Richard Feynman and Enrico Fermi, Albert Einstein and Edmund Halley did not come to ask throughout all of their dedication and work: "Who the hell is IMing me?" This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. ![]() | |
| ||
| | #53 (permalink) | |
| Slaying Bad Memes | Re: Pyro's Excel Goodies You are very welcome, Alexander. Thanks for asking. It would not bother me at all if I were to become a "resource" for all Hypographites who need spreadsheet expertise of any kind. Pyro, King of the Macros ![]() ---------------- Hypography Forums Moderator -- - - - - - What concerns me is not the way things are, but rather the way people think things are. Epictetus, Greek Philosopher The map is NOT the territory. Korzybski, Polish-American Philosopher Last edited by Pyrotex; 07-09-2008 at 12:28 PM. | |
| ||
| | #54 (permalink) | |
| Slaying Bad Memes | Re: Pyro's Excel Goodies BTW, Alexander, did you TRY the solution? Did it work? ---------------- Hypography Forums Moderator -- - - - - - What concerns me is not the way things are, but rather the way people think things are. Epictetus, Greek Philosopher The map is NOT the territory. Korzybski, Polish-American Philosopher | |
| ||
| | #55 (permalink) | |
| Resident USSRian | Re: Pyro's Excel Goodies Well, ok, we actually came up with a solution a while ago, i'm now trying to do conditional hides, and for the time being it's not working here's the macro code we use now for hiding the fields (courtesy of the person in the AV division, who's name i don't think makes any difference here): (btw no separate table required to restore the width )Code: Sub company_format_review()
Columns("D:N").Select
Selection.EntireColumn.Hidden = False
Range("A8").Select
With ActiveSheet.PageSetup
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.Orientation = xlLandscape
End With
End Sub
Sub Customer_review()
Range("E:E,G:G,H:H,I:I,J:J,K:K").Select
Range("K1").Activate
Selection.EntireColumn.Hidden = True
Range("A8").Select
With ActiveSheet.PageSetup
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.Orientation = xlPortrait
End With
End Sub
have a field that points to another field that does calculations for say labor, what i wanna do is hide the whole row if the value is nothing, and if there is a value, i dont want to hide the row. And i'll need to do this for a dozen or so rows... Pong back to you Pyro, help me Pyro-One-Kenobi, for you this is like fun, and perhaps not even anything challenging, and i don't like M$ Office ---------------- And remember that great question that Pierre-Simon Laplace and Sir Isaac Newton, Andrei Markov and David Hilbert, Richard Feynman and Enrico Fermi, Albert Einstein and Edmund Halley did not come to ask throughout all of their dedication and work: "Who the hell is IMing me?" This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. ![]() | |
| ||
| | #56 (permalink) | ||
| Slaying Bad Memes | Re: Pyro's Excel Goodies Okay, your friend's code will also work. Hiding a column produces the same effects as setting its width to zero. However, your friend's code is a tad sloppy. Instead of: Code: With ActiveSheet.PageSetup
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.Orientation = xlLandscape
End With
Code: With ActiveSheet.PageSetup
.PrintArea = ""
.Orientation = xlLandscape
End With
Quote:
Code: Sub Hide_Zeros()
Const cFlagOffset = 3
Range("LaborHeader").Select
Do Until Selection.Offset(0, cFlagOffset).Value = "XXXX"
Selection.Offset(1, 0).Select 'move down one row
If Selection.Value = 0 Then
Selection.EntireRow.Hidden = True
Else
Selection.EntireRow.Hidden = False
End If
Loop
Range("LaborHeader").Select
End Sub
And, this assumes that you have a "Flag" (XXXX, in this case) situated off to the side that marks the END of the Labor data. The offset of this Flag (3 columns to the right, in this case) is defined as a constant and its value is up to you. So, for example, if your Labor values are in column "H", then this macro looks for "XXXX" in column "K" in the the same row as your LAST Labor value (whether its zero or not). You can execute the macro with a keyboard shortcut, but I recommend a button. And you will definately want to show ALL rows from time to time, so you need this macro: Code: Sub Show_All()
Const cFlagOffset = 3
Range("LaborHeader").Select
Do Until Selection.Offset(0, cFlagOffset).Value = "XXXX"
Selection.Offset(1, 0).Select 'move down one row
Selection.EntireRow.Hidden = False
Loop
Range("LaborHeader").Select
End Sub
Code: For I = 1 to 12
...
Next I
---------------- Hypography Forums Moderator -- - - - - - What concerns me is not the way things are, but rather the way people think things are. Epictetus, Greek Philosopher The map is NOT the territory. Korzybski, Polish-American Philosopher Last edited by Pyrotex; 07-10-2008 at 01:44 PM. | ||
| |||
| | #57 (permalink) | |
| Resident USSRian | Re: Pyro's Excel Goodies ok this is what i settled on doing: to the right of the various fields i had to hide, i set a function with a value of, as an example: Code: =NOT(NOT(A1)) why? this effectively casts any value in the field as boolean, any 0, false, or null will be cast as false, and anything else as true, which is easy to check afterwards... Code: Sub hide_empty_fields_bottom()
For I = 1 To 10
Range("B" + CStr(I)).Select
Selection.EntireRow.Hidden = Selection.Value Xor True
Next I
Selection.EntireColumn.Hidden = True
End Sub
Sub unhide_empty_fields_bottom()
For I = 1 To 10
Range("B" + CStr(I)).Select
Selection.EntireRow.Hidden = False
Next I
Selection.EntireColumn.Hidden = True
End Sub
Problem i ran into was that the range function was returning a value that i couldn't even cast, it was so insanely weird, probalby due to what has to happen on the back end of the function or formatting or something.... so after hours of banging my head against the table, just rewrote it as such (it works now)---------------- And remember that great question that Pierre-Simon Laplace and Sir Isaac Newton, Andrei Markov and David Hilbert, Richard Feynman and Enrico Fermi, Albert Einstein and Edmund Halley did not come to ask throughout all of their dedication and work: "Who the hell is IMing me?" This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. ![]() | |
| ||
| | #58 (permalink) | |
| Slaying Bad Memes | Re: Pyro's Excel Goodies Your macros, and the use of NOT(NOT(cell)) seems extravagently over-complicated for such a simple task. ---------------- Hypography Forums Moderator -- - - - - - What concerns me is not the way things are, but rather the way people think things are. Epictetus, Greek Philosopher The map is NOT the territory. Korzybski, Polish-American Philosopher | |
| ||
| | #60 (permalink) | |
| Slaying Bad Memes | Re: Pyro's Excel Goodies Sheesh! Can't youse guys give me a break? Okay... [grumble]... back to the book review. ---------------- Hypography Forums Moderator -- - - - - - What concerns me is not the way things are, but rather the way people think things are. Epictetus, Greek Philosopher The map is NOT the territory. Korzybski, Polish-American Philosopher | |
| ||
![]() |
| Bookmarks |
| Tags |
| excel, formulas, macros, spreadsheet, spreadsheets, vba |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Excel 2007 compatibility | freeztar | User feedback | 11 | 01-29-2008 09:14 PM |
| How to convert Ms. Excel spreadsheet to MS. SQL? | cannonbow88 | Computer Science | 2 | 09-27-2006 05:52 AM |
| How to convert MS Excel format to My SQL? | Chloe | Computer Science | 5 | 08-11-2005 08:23 PM |
All times are GMT -8. The time now is 04:03 PM.





















