Question: Should I put code into the workbook module or work sheet module?

ckdragon

New Member
Joined
Apr 3, 2022
Messages
37
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi there

I currently have code in the module section which formats the sheet when call upon (via a button on said sheet)

The problem is, is that once I have pressed said button and the sheet is formatted, if I change any of the cell values the formatting doesn't change. I have multiple macros that link to that one button and if I repress it is stuffs up some other things in the sheet.

I am just wondering if I transfer the VBA formatting code I have from modules into the workbook module or the worksheet module if the formatting will automatically update when values are changed?

If so, is there any specific code I would need to include to action that?

Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I currently have code in the module section
Don't know what you mean by "the module section". A workbook can have sheet modules, standard modules, ThisWorkbook module, userform modules, class modules, but there is no "module section".

if I change any of the cell values the formatting doesn't change.
I'm not sure what you mean here. You just ran a macro that formats the sheet. What is it that you want to change afterwards just because you changed a cell value? What is your use case?

The short answer is probably that you should Worksheet_Change in the sheet module for this sheet. It will run anytime you change any value on that sheet.

In general you should use the ThisWorkbook module for any workbook-level events, worksheet modules for worksheet-level events and any code that applies to a specific sheet, and standard modules for code that doesn't fit into one of the above. This is very general rule of thumb and judgements need to be made for each design.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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