Procedure too Large - Ideas to simplify

rsfalkowski

New Member
Joined
Feb 25, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hello all,

This is my first post, so forgive me if its not the best.

I have some vba code that is acting as an inventory management programs for tools. It consist of about 350 if-elseif-end if statements (see below).

VBA Code:
If range("x9").Value - range("aa9").Value > 1 Then
MsgBox "Wrench1 currently checked out!", , "Inventory Alert"
ActiveCell.Offset(0, -1).Select
ActiveCell.ClearContents

ElseIf range("aa9").Value - range("x9").Value > 0 Then
MsgBox "Wrench1 currently checked in!", , "Inventory Alert"
ActiveCell.Offset(0, -1).Select
ActiveCell.ClearContents

The ("x9") and ("aa9") are referencing a CountIf formula on the active worksheet like so:

Code:
=COUNTIF($k$10:$p$10000,"Wrench1")

So essentially the VBA code is looking at this cell and if it is greater than 1, it means someone has tried to check out a tool that has been checked out, and it works the same for checking in a tool.

However, with 350 tools and 350 if statements, its become too large. Is there a way to consolidate counting tools and checking to see if they are checked-in/out within VBA?

Thanks in advance!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi & Welcome to MrExcel

You could put the code from the beginning and show several if elseif, to find a pattern and simplify the code.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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