Hello,
I have a loop that I've set up to go through each worksheet in a workbook and perform a series of tasks. The last task is to remove duplicates. The issue is that each worksheet could have a different number of columns. Is there a way to dynamically create an array for Excel to remove duplicates?
In the first worksheet, there are 22 columns, so this works:
However, the next spreadsheet only has 17 columns, so that won't work. I don't want to setup a case or if statement for each worksheet because a column may get added down the road and I don't want to have to touch the code going forward. I can get the last column with data, no problem. I just need to incorporate that in the above code as opposed to hard coded numbers.
Thanks in advance for any suggestions.
Roger
I have a loop that I've set up to go through each worksheet in a workbook and perform a series of tasks. The last task is to remove duplicates. The issue is that each worksheet could have a different number of columns. Is there a way to dynamically create an array for Excel to remove duplicates?
In the first worksheet, there are 22 columns, so this works:
Code:
rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)
However, the next spreadsheet only has 17 columns, so that won't work. I don't want to setup a case or if statement for each worksheet because a column may get added down the road and I don't want to have to touch the code going forward. I can get the last column with data, no problem. I just need to incorporate that in the above code as opposed to hard coded numbers.
Thanks in advance for any suggestions.
Roger