Excel VBA help

Steph_88

New Member
Joined
May 26, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

I'm completely new to Excel VBA and I'm struggling to get a macro to work.
I realise that for a newbie I might be trying to bite off more than I can chew *facepalm*

Context:
I have several 'product sheets' (14 in total) with each sheet containing information on the available versions for said product. The idea is that product managers will update these sheets as new product versions become available.

I then have another sheet (called 'customer products') which has all the product versions (from all 14 sheets) in the columns and a list of clients in the rows. This sheet provides a view of which customers have which products. Product managers will need to add any new versions to this sheet as well.

1653563945631.png


In an attempt to ensure there are no products missing from this sheet I want to include macros to cross-check the products between the 'customer products' sheet and the individual product sheets.

On each of the product sheets, I have the below macro which works fine.
There's a formula on each product sheet which flags when products are missing from the 'customer products' sheet. If errors are found, a warning message pops up on the relevant product sheet. l have this macro on all 14 product sheets.

Private Sub Worksheet_Calculate()
Static MyOldVal
If Range("$C$42").Value > 0 Then
Call Message_ProdWarning
End If

End Sub

1653564129907.png


I however want to stop the abovementioned macro from running when I'm on the 'customer products' sheet. I've tried the following but I just can't get it to work:

Private Sub Worksheet_Calculate_CMS()

Dim wb As Workbook
Set wb = ThisWorkbook

Dim ws As Worksheet
Set ws = wb.Sheets

For Each ws In wb.Worksheets
If ws.Name = "Customer products" Then
Exit Sub

Else

Static MyOldVal
If Range("$C$42").Value > 0 Then
Call Message_ProdWarning
End If

End If


End Sub

The other problem I have is that I want to run a different macro on the 'customer products' sheet. Again cross-checking that all products on this sheet have been added to the relevant product sheet. I've added formulas to flag if a product on the 'customer products' sheet is a duplicate or missing from the relevant product sheet. So here I need an error message based on 2 values changing - i.e. the error message should show if one or both of the relevant cells change.

I've added the following macro for this:

Sub Calculate_Customer()

Static MyOldVal
If Range("$E$217").Value > 0 Or Range("$E$219").Value > 0 Then
Call Message_CustWarning

End If


End Sub

The macro works when I "run" it in Visual Basic, but when I'm on the sheet, it doesn't work.

It should show me the error message below, but instead, it shows me the error message that should only show on the product sheets (the one I shared above).
I'm not sure if the issue is that when I change something on the 'customer products' sheets, it triggers the specified cell on the product sheet to change, which then calls the first error message (i.e. not the message below).

1653564344350.png



Am I overengineering this? I'd appreciate any feedback.
Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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