Forum Discussion
Need a macro to remove duplicate header rows but leave selected rows at the top
- Oct 09, 2021Thank you so much! This is gold!! I tested it using A1:C1 with E1:F1 as well and it works perfectly.
This is also much, much quicker than using the 2 short macros I had been using and much more flexible being able to select the cells rather than have the value hardcoded into the macro.
Regarding importing html files, do you have a solution to automate that? The main issue here is I need an input box where I can select the location of the file that will be converted because this will vary.
(I realise that should probably be a separate post)
Thanks so much for your help! I really appreciate it!
Felicity123 this seemed like an interesting problem/challenge but I didn't understand how/if the solution given would work for you, especially in the more generic case so I created another option for you to try. In the attached the macro (hot key is ctrl-m) will delete any other row in the file that matches any region you select. So if you select A1:C3 and D4:E4 (i.e. hold ctrl key when selecting additional areas) it will delete any row that has the same values in columns A:C as any of the rows 1-3 OR identical values in columns D&E as found in row 4.
I recommend NOT selecting entire rows as it will cause it to go very slow! only select the areas of interest. Also (although I didn't test it) if you select A1:C1 and E1:F1 it will treat those areas separately so if the values are the same as columns A:C OR the columns in E:F are the same then that row will be deleted.
Lastly, in the sample file you gave you will find that the 1 line of the header will not get deleted because the 2 are NOT identical (there is a difference in number of spaces I believe).
I hope this is useful.
This is also much, much quicker than using the 2 short macros I had been using and much more flexible being able to select the cells rather than have the value hardcoded into the macro.
Regarding importing html files, do you have a solution to automate that? The main issue here is I need an input box where I can select the location of the file that will be converted because this will vary.
(I realise that should probably be a separate post)
Thanks so much for your help! I really appreciate it!
- Felicity123Oct 09, 2021Brass Contributor
Felicity123 just solved last part with simple macro as follows:
Sub Open_Workbook_Dialog()
Dim my_FileName As Variant
my_FileName = Application.GetOpenFilename(FileFilter:="HTML Files,*.htm*;*.html*")
If my_FileName <> False Then
Workbooks.Open Filename:=my_FileName
End If
End Sub