Multiple settings If checks

DarkLife

New Member
Joined
Jun 11, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
I got a question about handling pre determine user settings and having tidy code without much of hassle repeating code with If checks (code below - strip version for better understanding - part of a class).

My main problem is there are bunch of sub subs/functions that works depending on the first two sets ("PTCI_HighestDate", "PTCI_HighestDateExtra") and depending if PTCI_HighestDateExtra gets defined then proces withi correct case (there are more user settings checks)

I don't know how can I put them into one place without just moving the checks from one place to another.

I try :
- separate cases into subs but that just move the problem not eredecatit it.
- Put if checks before running accual subs/function - creats ungly cluester hard to navigate.
- Creating more functions with checks in them - hard to navigate in that function once again move the problem not eredecatit it.

Keep in mind that there is more code (If statments ect.)
I just want to know If there is even a way to make the code more tide without losing too much preformence (I value tidenes over preformence)

Also this code gets repeted 500+ times without any changes in settings.
My only guess is to do some magic before even running the loop but that just may not even by posible for my case.

VBA Code:
Sub CreatNewCNWithHighestDate(Item As cPivotTableCustomItem)
Dim fso As FileSystemObject
Dim PTCI_HighestDate As cPivotTableCustomItem
Dim PTCI_HighestDateExtra As cPivotTableCustomItem
Dim CorrectSubFolderPath As String

'// add defineds for PathCNK
Dim CorrectDate As String

Set fso = New FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

Set PTCI_HighestDate = Item.SubItems(Item.SubItems.Count)
Set PTCI_HighestDateExtra = ItemExtra(PTCI_HighestDate)

'HighestDateONLYNoneCNK = 0
'CNKONLY = 1
'ALL = 2
'ALLAndCNKWithHighestDate = 3

'// Creating folders and copying
'// Selects correct way of creating files on conditon and avaible sorces
Select Case pSettings.ItemsSubFoldersCreation
    Case 0, 1 And PTCI_HighestDateExtra Is Nothing  '// Creat folders only if there ishighestdate item
        '// Uses PTCI_HighestDate
        '//Define full path
        If pSettings.something Then '// Delete (if needed) and crete new folder
        If pSettings.something Then '// Copy paste templet
        If pSettings.something Then '// Check If there was new PP
        If pSettings.something Then '// Copy paste Pohoda files

'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Case 1, 2 And Not PTCI_HighestDateExtra Is Nothing  '// Creat folders only if there is highestdateCNK item
        '// Uses PTCI_HighestDateExtra
        '//Define full path
        If pSettings.something Then '// Delete (if needed) and crete new folder
        If pSettings.something Then '// Creat ShortCut to prewies CNK folder
        If pSettings.something Then '// Copy paste all excels
        If pSettings.something Then '// Check If there was new PP
        If pSettings.something Then '// Copy paste Pohoda files
        If pSettings.something Then '// Copy paste all outlook
        If pSettings.something Then '//Search and copy Email

'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Case 3 And PTCI_HighestDateExtra Is Nothing   '// It also checks If highes date isnt same as Highest CNK
        '// Uses PTCI_HighestDate
        '//Define full path
        If pSettings.something Then '// Delete (if needed) and crete new folder
        If pSettings.something Then '// There isnt CNK
        If pSettings.something Then '// Copy paste Pohoda files
        If pSettings.something Then '// Copy paste templet
        If pSettings.something Then '// Check If there was new PP
        
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Case 3 And Not PTCI_HighestDateExtra Is Nothing
        '// Uses PTCI_HighestDateExtra
        '//Define full path
        If pSettings.something Then '// Delete (if needed) and crete new folder
        If pSettings.something Then '// Copy paste Pohoda files
        If pSettings.something Then '// Copy paste all outlook
        If pSettings.something Then '//Search and copy Email
        
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Case 4 And PTCI_HighestDateExtra Is Nothing
        '// Uses PTCI_HighestDate
        '//Define full path
        If pSettings.something Then '// Delete (if needed) and crete new folder
        If pSettings.something Then '// Copy paste Pohoda files
        If pSettings.something Then '// Copy paste all outlook
        If pSettings.something Then '//Search and copy Email
End Select
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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