Need a longer than standard length macro and with ‘if this then that’ conditions?


If you have ever tried to record a macro only to later discover that you’re getting ‘macro too long’ error message, you should consider to split a big macro project more that 1,400 lines) into several parts.  Once you record separate macros (or, alternatively, you can record the whole thing and later cut it manually in code into several macros – requires more than just a very basic skills and so not recommended for novices) you need to make a new macro which will ‘call’ part A, B, C etc. one after another to execute the full project.

In below example you can see visual basic command ‘call’ + [macro name] repeating several times – this runs each macro within the bigger picture. I have also used ‘If’ condition – you can set the criteria in the master macro file (xlsm – macro enable spreadsheet) and then using the drop down menu use your own way to customise your report.

See the example code below.

Sub Big Project()
' Big Project Macro
If Range("l16").Value = "Yes" Then
 Call Project_Presorting
End If
If Range("l12").Value = "Yes" Then
 Call Project_PartA
 Call Project _PartB
End If
If Range("l12").Value = "No" Then (this condition excludes option of running macro called Project_PartB)
 Call Project_PartA
End If
If Range("l18").Value = "Yes" Then
 Call Project_Part C
End If
End Sub



Your Thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s