ValuationMan
New Member
- Joined
- Jun 30, 2017
- Messages
- 49
- Office Version
- 365
- Platform
- Windows
- MacOS
I have a macro that loops through Column A to remove outliers in the range. Using the offset function, the loop is used for Column B, Column C, etc. The basic structure of the code is below.
The loops work as intended, but I'm wondering if the If ActiveSheet.name code could be more efficient. In a workbook, I would use Index Match or Vlookup to look up a reference table. I'm curious if anything like exists for use in the backend instead of using all of those If statements.
Code:
dim i as integer
i=1
dim ColumnOffset as integer
'the value of ColumnOffset changes based on the sheet
If ActiveSheet.name="Sheet1" then ColumnOffset=3
If ActiveSheet.name="Sheet2" then ColumnOffset=4
If ActiveSheet.name="Sheet3" then ColumnOffset=2
Do While i <= ColumnOffset[INDENT]'additional code that uses ColumnOffset to work on Column A then B then C then ...[/INDENT]
i=i+1
loop
The loops work as intended, but I'm wondering if the If ActiveSheet.name code could be more efficient. In a workbook, I would use Index Match or Vlookup to look up a reference table. I'm curious if anything like exists for use in the backend instead of using all of those If statements.