Delete rows - use variables in array stmt?

bobkap

Active Member
Joined
Nov 22, 2009
Messages
313
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I need to remove duplicates when columns 3 and 8 match. This line works fine:
Range(Cells(2, 1), Cells(finalrow, finalcol)).RemoveDuplicates Columns:=Array(3, 8), Header:=xlYes

But, I prefer to use variables of course. I've tried as below by replacing the 3 and 8 with a variable but it always bombs out. Even though it made no sense. I even tried putting quotes on the variables but still no dice.
Range(Cells(2, 1), Cells(finalrow, finalcol)).RemoveDuplicates Columns:=Array(email, yearbk), Header:=xlYes

Is there no way to use variables this way?

Any help is most appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Please post the code or part of the code, so someone can see & work on.

What is the declared data type of email & yearbk?
 
Upvote 0
Thanks. After some trial and error I was able to get that to work. BUT, another problem - This keeps getting an error that this line "yearnum = year(curdate)" expects an array?? I thought I had syntax correct but I guess not. Might you have a suggestion please?

'Extract year only from course date
cordate = Application.match("Course Date", Range("1:1"), 0)
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For counter2 = 2 To finalrow
curdate = Cells(counter2, cordate)
yearnum = year(curdate)
Cells(counter2, courseyear) = yearnum
Next counter2
 
Upvote 0
I'm sorry.
Hope some experts will look into this & have a solution for you.
 
Upvote 0

Forum statistics

Threads
1,214,879
Messages
6,122,065
Members
449,064
Latest member
scottdog129

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top