Excel Programing

Chat about a topic supported by books, TED Talks, podcasts, personal experience, philosophies of mankind mingled with humor (shout out to IOT), and maybe we’ll even do a google hangout or conference call once a month.
Post Reply
User avatar
Just This Guy
Posts: 1549
Joined: Fri Oct 21, 2016 3:30 pm
Location: Almost Heaven

Excel Programing

Post by Just This Guy »

Anyone here have experience writing macros in Excel? I am working on a project for work and can't seam to get it to work the way I want it to. I was wondering if anyone here can help mu trouble shoot what I am doing wrong.
"The story so far: In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." -- Douglas Adams
Corsair
Posts: 3080
Joined: Fri Oct 14, 2016 9:58 am
Location: Phoenix

Re: Excel Programing

Post by Corsair »

Maybe. What are you trying to do?
User avatar
Just This Guy
Posts: 1549
Joined: Fri Oct 21, 2016 3:30 pm
Location: Almost Heaven

Re: Excel Programing

Post by Just This Guy »

I'm trying to create a universal reporting form. So based on what they select in a specific cell, the sheet would automatically hide or unhide certain rows.
"The story so far: In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." -- Douglas Adams
Corsair
Posts: 3080
Joined: Fri Oct 14, 2016 9:58 am
Location: Phoenix

Re: Excel Programing

Post by Corsair »

The macro programming does include commands for hiding rows and columns such as:

Rows(2).Hidden = True

That's a full macro programming command and not necessarily an update based in a cell formula. I do not know of a cell formula that would change the "hide" property of a row or column. It seems like something that should exist.
Reuben
Posts: 1455
Joined: Sat Oct 28, 2017 3:01 pm

Re: Excel Programing

Post by Reuben »

What Corsair said, except that a formula that alters cell attributes should not exist.

(I can make bold statements like this because I'm part of a team at Microsoft Research that consults with Excel's designers on the design of the formula language. I'll follow that posturing up with an explanation, though.)

One of the most important properties of workbook recalc - the cell value updates that happen after you alter a formula - is that it doesn't matter what order the formulas are recalculated in. If order mattered, you would get different answers depending on which cells you edit, because recalc only recalculates the edited cells and the cells that depend on them. Finance companies across the globe would rebel and switch to Google Sheets. Auditors would cry themselves to sleep.

Because there are worksheet functions that are sensitive to which rows are hidden, such as the frequently used SUBTOTAL which can skip hidden rows, allowing a formula to change the hidden attribute would make recalc order matter. If one formula hid a row and another formula showed it, any SUBTOTAL that included that row would give different answers depending on whether each of those formulas was recalculated and in which order. The last recalculated would always have its way.

To avoid all such ambiguities now and in the future, Excel locks down every open workbook during recalc. Not even VBA functions can change them during recalc.

--

Just This Guy: I think you can make Excel do what you want anyway. Corsair's command should work as long as it's run after recalc.

This looks like the kind of thing you want:

https://docs.microsoft.com/en-us/office ... lls-change

I don't know a lot about VBA, but I think by the time Worksheet_Change is called, the cells you want to monitor will have their new values in them, and the workbook will be unlocked so you can hide or show rows.
Learn to doubt the stories you tell about yourselves and your adversaries.
User avatar
Red Ryder
Posts: 4182
Joined: Sun Oct 16, 2016 5:14 pm

Re: Excel Programing

Post by Red Ryder »

Wow Reuben, I think I had an excelgasm!

Keep talking dirty man, that’s sexy stuff!
“It always devolves to Pantaloons. Always.” ~ Fluffy

“I switched baristas” ~ Lady Gaga

“Those who do not move do not notice their chains.” ~Rosa Luxemburg
Reuben
Posts: 1455
Joined: Sat Oct 28, 2017 3:01 pm

Re: Excel Programing

Post by Reuben »

Red Ryder wrote: Fri Mar 06, 2020 8:59 am Wow Reuben, I think I had an excelgasm!

Keep talking dirty man, that’s sexy stuff!
Drag-fill. Relative references. Manual recalc. NPV. Data validation. Name manager! Conditional formatting!

Did you know that if A1 is blank, then A1=False and A1=0 and A1=""? That's my dirtiest secret.
Learn to doubt the stories you tell about yourselves and your adversaries.
User avatar
wtfluff
Posts: 3687
Joined: Mon Oct 17, 2016 3:20 pm
Location: Worshiping Gravity / Pulling Taffy

Re: Excel Programing

Post by wtfluff »

Reuben wrote: Fri Mar 06, 2020 1:35 pm
Red Ryder wrote: Fri Mar 06, 2020 8:59 am Wow Reuben, I think I had an excelgasm!

Keep talking dirty man, that’s sexy stuff!
Drag-fill. Relative references. Manual recalc. NPV. Data validation. Name manager! Conditional formatting!

Did you know that if A1 is blank, then A1=False and A1=0 and A1=""? That's my dirtiest secret.
What aboot pivot tables?
Faith does not give you the answers, it just stops you asking the questions. -Frater Ravus

IDKSAF -RubinHighlander

Gave up who I am for who you wanted me to be...
Reuben
Posts: 1455
Joined: Sat Oct 28, 2017 3:01 pm

Re: Excel Programing

Post by Reuben »

wtfluff wrote: Fri Mar 06, 2020 2:07 pm
Reuben wrote: Fri Mar 06, 2020 1:35 pm
Red Ryder wrote: Fri Mar 06, 2020 8:59 am Wow Reuben, I think I had an excelgasm!

Keep talking dirty man, that’s sexy stuff!
Drag-fill. Relative references. Manual recalc. NPV. Data validation. Name manager! Conditional formatting!

Did you know that if A1 is blank, then A1=False and A1=0 and A1=""? That's my dirtiest secret.
What aboot pivot tables?
Ssshhh! Do you want to get him PREGNANT?
Learn to doubt the stories you tell about yourselves and your adversaries.
User avatar
wtfluff
Posts: 3687
Joined: Mon Oct 17, 2016 3:20 pm
Location: Worshiping Gravity / Pulling Taffy

Re: Excel Programing

Post by wtfluff »

Reuben wrote: Fri Mar 06, 2020 2:28 pm
wtfluff wrote: Fri Mar 06, 2020 2:07 pm
Reuben wrote: Fri Mar 06, 2020 1:35 pm

Drag-fill. Relative references. Manual recalc. NPV. Data validation. Name manager! Conditional formatting!

Did you know that if A1 is blank, then A1=False and A1=0 and A1=""? That's my dirtiest secret.
What aboot pivot tables?
Ssshhh! Do you want to get him PREGNANT?
Boy Howdy!

(How soon before a mod marks this thread NSFW? :D )
Faith does not give you the answers, it just stops you asking the questions. -Frater Ravus

IDKSAF -RubinHighlander

Gave up who I am for who you wanted me to be...
User avatar
Red Ryder
Posts: 4182
Joined: Sun Oct 16, 2016 5:14 pm

Re: Excel Programing

Post by Red Ryder »

wtfluff wrote: Fri Mar 06, 2020 2:31 pm
Reuben wrote: Fri Mar 06, 2020 2:28 pm
wtfluff wrote: Fri Mar 06, 2020 2:07 pm

What aboot pivot tables?
Ssshhh! Do you want to get him PREGNANT?
Boy Howdy!

(How soon before a mod marks this thread NSFW? :D )
Aboot? Now your adding a Canadian accent with excel dirty talk? How do you type drooling sounds?

Confession: my girlfriend was Canadian in high school and so I have this thing for Canadian accents. One of the ladies in our corporate office is Canadian so I’ll sometimes call and ask random questions just to chat her up just to hear a thick heavy accent.
“It always devolves to Pantaloons. Always.” ~ Fluffy

“I switched baristas” ~ Lady Gaga

“Those who do not move do not notice their chains.” ~Rosa Luxemburg
Reuben
Posts: 1455
Joined: Sat Oct 28, 2017 3:01 pm

Re: Excel Programing

Post by Reuben »

Red Ryder wrote: Fri Mar 06, 2020 4:23 pm
wtfluff wrote: Fri Mar 06, 2020 2:31 pm
Reuben wrote: Fri Mar 06, 2020 2:28 pm

Ssshhh! Do you want to get him PREGNANT?
Boy Howdy!

(How soon before a mod marks this thread NSFW? :D )
Aboot? Now your adding a Canadian accent with excel dirty talk? How do you type drooling sounds?
bwleuuuhhfup. mlehhhchchghugfffffffffp. *wipes cheek*
Learn to doubt the stories you tell about yourselves and your adversaries.
User avatar
wtfluff
Posts: 3687
Joined: Mon Oct 17, 2016 3:20 pm
Location: Worshiping Gravity / Pulling Taffy

Re: Excel Programing

Post by wtfluff »

Red Ryder wrote: Fri Mar 06, 2020 4:23 pm
wtfluff wrote: Fri Mar 06, 2020 2:31 pm
Reuben wrote: Fri Mar 06, 2020 2:28 pm

Ssshhh! Do you want to get him PREGNANT?
Boy Howdy!

(How soon before a mod marks this thread NSFW? :D )
Aboot? Now your adding a Canadian accent with excel dirty talk? How do you type drooling sounds?

Confession: my girlfriend was Canadian in high school and so I have this thing for Canadian accents. One of the ladies in our corporate office is Canadian so I’ll sometimes call and ask random questions just to chat her up just to hear a thick heavy accent.
Doh.

Sorry aboot that. Dang it... Did it again!

I only pretend to be from the Great White North now and again...
Faith does not give you the answers, it just stops you asking the questions. -Frater Ravus

IDKSAF -RubinHighlander

Gave up who I am for who you wanted me to be...
Post Reply