I'm trying to clear duplicate data out of cells. I have a VBA to clear columns A and C and keep the first instance. But because column B might be the same throughout the report, it will clear out what I want to keep. The only way I see to do it is to look at the same cell in column D and if it has "System Firmware" it should be kept. All other instances be cleared. So in my example I would like to keep B5 and B14 because they are the first instance. All others would be cleared. All of my reports will be different. Some may have 1 hostname. Others may have 5 different hostnames. I also posted the code I use to clear data out of columns A and C.
Sub RemoveRepeatingStringsA()
Dim BaseStr As String, CurrStr As String
Dim EndRow As Long
EndRow = Range("A" & Rows.Count).End(xlUp).Row
BaseStr = Range("A1").Value
Application.ScreenUpdating = False
For Iter = 2 To EndRow
CurrStr = Range("A" & Iter).Value
If CurrStr = BaseStr Then
Range("A" & Iter).Value = vbNullString
Else
BaseStr = Range("A" & Iter).Value
End If
Next Iter
Application.ScreenUpdating = True
RemoveRepeatingStringsB
End Sub
PERSONAL.XLSB | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | |||
1 | |||||||||||||
2 | |||||||||||||
3 | |||||||||||||
4 | Hostname | Machine Type | serial number | component | machine data | machine data | machine data | machine data | machine data | machine data | machine data | ||
5 | computer 1 | 1234 | 5678901 | System Firmware | data | data | data | data | data | data | data | ||
6 | computer 1 | 1234 | 5678901 | ent0 | data | data | data | data | data | data | data | ||
7 | computer 1 | 1234 | 5678901 | ent1 | data | data | data | data | data | data | data | ||
8 | computer 1 | 1234 | 5678901 | ent2 | data | data | data | data | data | data | data | ||
9 | computer 1 | 1234 | 5678901 | pdisk0 | data | data | data | data | data | data | data | ||
10 | computer 1 | 1234 | 5678901 | pdisk1 | data | data | data | data | data | data | data | ||
11 | computer 1 | 1234 | 5678901 | pdisk2 | data | data | data | data | data | data | data | ||
12 | computer 1 | 1234 | 5678901 | tape0 | data | data | data | data | data | data | data | ||
13 | computer 1 | 1234 | 5678901 | tape1 | data | data | data | data | data | data | data | ||
14 | computer 2 | 1234 | abc1234 | System Firmware | data | data | data | data | data | data | data | ||
15 | computer 2 | 1234 | abc1234 | ent0 | data | data | data | data | data | data | data | ||
16 | computer 2 | 1234 | abc1234 | ent1 | data | data | data | data | data | data | data | ||
17 | computer 2 | 1234 | abc1234 | ent2 | data | data | data | data | data | data | data | ||
18 | computer 2 | 1234 | abc1234 | pdisk0 | data | data | data | data | data | data | data | ||
19 | computer 2 | 1234 | abc1234 | pdisk1 | data | data | data | data | data | data | data | ||
20 | computer 2 | 1234 | abc1234 | pdisk2 | data | data | data | data | data | data | data | ||
21 | computer 2 | 1234 | abc1234 | tape0 | data | data | data | data | data | data | data | ||
22 | computer 2 | 1234 | abc1234 | tape1 | data | data | data | data | data | data | data | ||
Sheet |
Sub RemoveRepeatingStringsA()
Dim BaseStr As String, CurrStr As String
Dim EndRow As Long
EndRow = Range("A" & Rows.Count).End(xlUp).Row
BaseStr = Range("A1").Value
Application.ScreenUpdating = False
For Iter = 2 To EndRow
CurrStr = Range("A" & Iter).Value
If CurrStr = BaseStr Then
Range("A" & Iter).Value = vbNullString
Else
BaseStr = Range("A" & Iter).Value
End If
Next Iter
Application.ScreenUpdating = True
RemoveRepeatingStringsB
End Sub