mhrsolanki2020
New Member
- Joined
- May 21, 2017
- Messages
- 3
Hello,
I am working on a project in which I need to keep a list of unique patient. As and when new entries are added to the main database sheet, i will add the name to the patientMaster list and then use remove duplicate method of Range function. The code being
The problem is, currently I have 3 Columns viz, Name, Date Of Birth and Family Details. However, down the line, new columns might be added. Say i add 2 more columns, then i would have to re-edit the code to
My question is: " Is there any way that I can do this dynamically?"
I do have a solution using IIf statements which counts the number of columns and then sets the Array
But this is very inefficient. If you can help me with any other efficient solution?
Mihir Solanki
I am working on a project in which I need to keep a list of unique patient. As and when new entries are added to the main database sheet, i will add the name to the patientMaster list and then use remove duplicate method of Range function. The code being
Code:
patientMaster.Range(patientMaster).RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
The problem is, currently I have 3 Columns viz, Name, Date Of Birth and Family Details. However, down the line, new columns might be added. Say i add 2 more columns, then i would have to re-edit the code to
Code:
patientMaster.Range(patientMaster).RemoveDuplicates Columns:=Array(1, 2, 3,[U][B]4,5[/B][/U]), Header:=xlYes
My question is: " Is there any way that I can do this dynamically?"
I do have a solution using IIf statements which counts the number of columns and then sets the Array
Code:
'numOfCol has the number of columns
patientMaster.Range(patientMaster).RemoveDuplicates Columns:=IIf(numOfCol = 7, (Array(1, 2, 3,4,5,6,7),IIf(numOfCol = 6,Array(1,2,3,4,5,6),IIf(numOfCol = 5,Array(1,2,3,4,5),IIf(numOfCol=4,Array(1,2,3,4),Array(1,2,3))))) , Header:=xlYes
But this is very inefficient. If you can help me with any other efficient solution?
Mihir Solanki