yes, let me try...the input is a network configuration file, the code is suppose to extract & merge found data and then separate each cell into multiple col's...
Error Output:
[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 56"]
<colgroup><col></colgroup><tbody>[TR]
[TD]GE1/0/1[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]GE1/0/2[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]GE1/0/3
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]FE2/0/1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]FE2/0/2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]FE2/0/3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]FE3/0/1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]FE3/0/2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]FE3/0/3[/TD]
[/TR]
</tbody>[/TABLE]
Output should be:
[TABLE="width: 500"]
<tbody>[TR]
[TD]GE1/0/1[/TD]
[TD]FE2/0/1[/TD]
[TD]FE3/0/1[/TD]
[/TR]
[TR]
[TD]GE1/0/2[/TD]
[TD]FE2/0/2[/TD]
[TD]FE3/0/2[/TD]
[/TR]
[TR]
[TD]GE1/0/3[/TD]
[TD]FE2/0/3[/TD]
[TD]FE3/0/3[/TD]
[/TR]
</tbody>[/TABLE]
Here is the full code:
Dim Filter As String, Title As String, FilterIndex As Integer, Filename As Variant, LastRow As Long
Dim rng As Range, c As Range, nb As Range, x As String, varLastRow, rw As Long, a As Range, b As Range, ra As Long, rb As Long
'***************************************************Function To Get Information From A File
Sub MacrosCFG()
'***File types
Filter = "Excel Files (*.xls),*.xls," & _
"Text Files (*.txt),*.txt," & _
"All Files (*.*),*.*"
FilterIndex = 3 'Default Filter to *.*
Title = "SELECT FILE TO OPEN:" 'Caption
'*************************************Start Drive & Path
ChDir ("C:\")
With Application
'***Name selected File
Filename = .GetOpenFilename(Filter, FilterIndex, Title, ActiveWorkbook.Name)
Workbooks.Open Filename, ReadOnly:=True
End With
'***Exit With No Selection
If Filename = False Then
MsgBox "NO FILE WAS SELECTED!", vbExclamation
Exit Sub
End If
'***Open File & Extract Data
'Workbooks.Open Filename, ReadOnly:=True
' If filename = true than
' MsgBox Filename, vbInformation, "DATA EXTRACTED FROM:"
'If filename = false than
'**************************************Modify Data In Cells
'***replace wanted content in cells
Application.ReplaceFormat.Clear
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "hostname ", "", xlPart, , False, , False, True
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "description ", "", xlPart, , False, , False, True
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "interface ", "", xlPart, , False, , False, True
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "switchport access vlan ", "", xlPart, , False, , False, True
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "*ip address", "", xlPart, , False, , False, True
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "GigabitEthernet", "GE", xlPart, , False, , False, True
Range("A1", Cells(Rows.Count, "A").End(xlUp)).Replace "FastEthernet", "FE", xlPart, , False, , False, True
Application.ReplaceFormat.Clear
'***combine wanted content of 3 cells in a row
rw = 1
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
If c.Value Like "*FE*" Or c.Value Like "*GE*" Then
Range("B" & rw).Value = c.Value & " " & c.Offset(1).Value & " (Vlan" & c.Offset(2).Value & ")"
'ElseIf c.Value Like "Vlan*" Then
' Range("B" & rw).Value = c.Value & " " & c.Offset(1).Value & " " & c.Offset(2).Value
rw = rw + 1
End If
Next c
[A:A].Delete
'********************************************seperate cells into 48 cell sets
'***move content to col B
rw = 0
kb = 3
kc = 3
kd = 3
ke = 3
kf = 3
kg = 3
kh = 3
ki = 3
kj = 3
kk = 3
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
If c.Value Like "FE1*" Then
Range("B" & kb).Value = c.Value
Range("B" & kb).Interior.ColorIndex = 43
ElseIf c.Value Like "GE1*" Then
Range("B" & kb).Value = c.Value
Range("B" & kb).Interior.ColorIndex = 3
ElseIf c.Value Like "FE2*" Then
Range("C" & kc).Value = c.Value
Range("C" & kc).Interior.ColorIndex = 43
ElseIf c.Value Like "GE2*" Then
Range("C" & kc).Value = c.Value
Range("C" & kc).Interior.ColorIndex = 3
ElseIf c.Value Like "FE3*" Then
Range("D" & kd).Value = c.Value
Range("D" & kd).Interior.ColorIndex = 43
ElseIf c.Value Like "GE3*" Then
Range("D" & kd).Value = c.Value
Range("D" & kd).Interior.ColorIndex = 3
ElseIf c.Value Like "FE4*" Then
Range("E" & ke).Value = c.Value
Range("E" & ke).Interior.ColorIndex = 43
ElseIf c.Value Like "GE4*" Then
Range("E" & ke).Value = c.Value
Range("E" & ke).Interior.ColorIndex = 3
ElseIf c.Value Like "FE5*" Then
Range("F" & kf).Value = c.Value
Range("F" & kf).Interior.ColorIndex = 43
ElseIf c.Value Like "GE5*" Then
Range("F" & kf).Value = c.Value
Range("F" & kf).Interior.ColorIndex = 3
ElseIf c.Value Like "FE6*" Then
Range("G" & kg).Value = c.Value
Range("G" & kg).Interior.ColorIndex = 43
ElseIf c.Value Like "GE6*" Then
Range("G" & kg).Value = c.Value
Range("G" & kg).Interior.ColorIndex = 3
ElseIf c.Value Like "FE7*" Then
Range("H" & kh).Value = c.Value
Range("H" & kh).Interior.ColorIndex = 43
ElseIf c.Value Like "GE7*" Then
Range("H" & kh).Value = c.Value
Range("H" & kh).Interior.ColorIndex = 3
ElseIf c.Value Like "FE8*" Then
Range("I" & ki).Value = c.Value
Range("I" & ki).Interior.ColorIndex = 43
ElseIf c.Value Like "GE8*" Then
Range("I" & ki).Value = c.Value
Range("I" & ki).Interior.ColorIndex = 3
ElseIf c.Value Like "FE9*" Then
Range("J" & kj).Value = c.Value
Range("J" & kj).Interior.ColorIndex = 43
ElseIf c.Value Like "GE9*" Then
Range("J" & kj).Value = c.Value
Range("J" & kj).Interior.ColorIndex = 3
ElseIf c.Value Like "Vl*" Then
Range("K" & kk).Value = c.Value
End If
kb = kb + 1
kc = kc + 1
kd = kd + 1
ke = ke + 1
kf = kf + 1
kg = kg + 1
kh = kh + 1
ki = ki + 1
kj = kj + 1
kk = kk + 1
Next c
'***clear content in col A
Range("A1", Range("A" & Rows.Count).End(xlUp)).Select
Selection.ClearContents
Columns("A:Z").EntireColumn.AutoFit
Range("A1").Select
End Sub