Solved

remove duplicate headers

Posted on 2014-09-11
10
215 Views
Last Modified: 2014-09-11
after opening certain csv files there are sometimes many duplicate header rows. Is there a short quick piece of VBA that can remove all of the duplicate header but leave the main [row 1] header.

thanks
0
Comment
Question by:Jagwarman
  • 5
  • 4
10 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 40317004
You should never have "duplicate header rows" in CSV files. Is that because there is a word/line wrap in headers, maybe? So they build two instead of only one line? Anyway, that is far from any standard format.

There cannot be any generic code able to remove "duplicate header rows", because usually those rows would just look like data. You need special knowledge, like "first column cannot be a string", to check for superfluous lines.
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40317027
Hi,

pls try

Sub macro()
Dim arrFirstRow As Variant
Dim arrNextRow As Variant
Set myRange = Range(Range("A1"), Range("A1").End(xlToRight))
arrFirstRow = myRange
strFirstRow = Join(WorksheetFunction.Index(arrFirstRow, 1, 0), ",")
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For Idx = LastRow To 2 Step -1
    Set myRange = Range(Range("A" & Idx), Range("A" & Idx).End(xlToRight))
    arrNextRow = myRange
    strNextRow = Join(WorksheetFunction.Index(arrNextRow, 1, 0), ",")
    If strNextRow = strFirstRow Then
        Cells(Idx, 1).EntireRow.Delete
    End If
Next

End Sub

Regards
0
 

Author Comment

by:Jagwarman
ID: 40317098
Hi Rgonzo, that ran but didn't actually do anything ?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40317108
Pls send a dummy
0
 

Author Comment

by:Jagwarman
ID: 40317183
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40317197
The problem was that they weren't the same

"User-ID" became " User-ID"

Corrected Code

Sub macro()
Dim arrFirstRow As Variant
Dim arrNextRow As Variant
Set myRange = Range(Range("A1"), Range("A1").End(xlToRight))
arrFirstRow = myRange
strFirstRow = Join(WorksheetFunction.Index(arrFirstRow, 1, 0), ",")
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For Idx = LastRow To 2 Step -1
    Set myRange = Range(Range("A" & Idx), Range("A" & Idx).End(xlToRight))
    arrNextRow = myRange
    strNextRow = Join(WorksheetFunction.Index(arrNextRow, 1, 0), ",")
    If strNextRow = strFirstRow Or strNextRow = " " & strFirstRow Then
        Cells(Idx, 1).EntireRow.Delete
    End If
Next

End Sub
0
 

Author Comment

by:Jagwarman
ID: 40317226
Rgonzo you provided me with code back in dec to copy all tabs to a new workbook. I just tried to use it and it says "Can't insert the sheets into the destination workbook because it contains fewer rows and columns...... sure enough when I look at the new workbook it only has 64k rows even though I am opening it from Excel 2010 any ideas?
0
 

Author Comment

by:Jagwarman
ID: 40317232
The remove headers is perfect thanks
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40317244
if you try to copy from a XLSM or XLSX file to a XLS this problem will appear
0
 

Author Comment

by:Jagwarman
ID: 40317927
ok tks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question