justanotheruser
Board Regular
- Joined
- Aug 14, 2010
- Messages
- 96
Hi all,
I have some VBA code that I'm using for an Invoice system. As part of the system, it needs to call up a certain function based on the sheet name. I have two choices, I can either make 4 copies of the same code (when you press a button, called "Process Invoice", it runs a macro that runs a few different functions at the same time), and then just change VATCopy1, VATCopy2, VATCopy3, VATCopy4 and assign a different macro to each sheet, or use an IF formula.
So my code is:
Basically, I'm trying to do something that says:
Those are the four conditions I need to put in my code.
My attempt (for the first 2 sheets) is this:
However this returns the Compile Error Block if without End if.
Can anyone please help?
Thanks in advance!
I have some VBA code that I'm using for an Invoice system. As part of the system, it needs to call up a certain function based on the sheet name. I have two choices, I can either make 4 copies of the same code (when you press a button, called "Process Invoice", it runs a macro that runs a few different functions at the same time), and then just change VATCopy1, VATCopy2, VATCopy3, VATCopy4 and assign a different macro to each sheet, or use an IF formula.
So my code is:
Code:
Call VATCopy1 'This will do the VATCopy function and copy the relevant data to the "Database" sheet
Basically, I'm trying to do something that says:
- if Sheet Name is "VAT", run VATCopy1
- if Sheet Name is "VAT & Disc", run VATCopy2
- if Sheet Name is "Zero VAT", run VATCopy3
- if Sheet Name is "Zero VAT & Disc", run VATCopy4
Those are the four conditions I need to put in my code.
My attempt (for the first 2 sheets) is this:
Code:
Dim wsSheet As Worksheet
For Each wsSheet In Worksheets
If wsSheet.Name = "VAT" Then
Call VATCopy1 'This will do the VATCopy function and copy the relevant data to the "Database" sheet from the sheet named "VAT"
Else
If wsSheet.Name = "VAT & Disc" Then
Call VATCopy2 'This will do the VATCopy function and copy the relevant data to the "Database" sheet from the sheet named "VAT & Disc"
End If
However this returns the Compile Error Block if without End if.
Can anyone please help?
Thanks in advance!