Re: Finding Variables and inserting row below them from a list
Bobd
Give this a try and let me know if it's doing what you want.
Code
Sub Inserter()
Dim a, b(), i As Long, j As Long, k As Long, lRow As Long, x As Long, z(6), zz
Dim sDic As Object, ws As Worksheet
Set sDic = CreateObject("Scripting.Dictionary")
With Sheets("List Sheet")
a = .Range("A1:J7").Value
End With
For i = 2 To UBound(a, 1)
For j = 4 To UBound(a, 2)
z(j - 4) = a(i, j)
Next
sDic.Item(a(i, 1)) = z
Next
For Each ws In Worksheets
x = 0
If ws.Name <> "List Sheet" Then
With ws
lRow = .Range("A" & Rows.Count).End(xlUp).Row
a = .Range("A3", .Range("G" & lRow))
ReDim b(1 To UBound(a, 1) * 2, 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
x = x + 1
For j = 1 To UBound(a, 2)
b(x, j) = a(i, j)
Next
If sDic.exists(a(i, 1)) Then
x = x + 1
zz = sDic.Item(a(i, 1))
For k = 0 To UBound(zz)
b(x, k + 1) = zz(k)
Next
End If
Next
With .Range("A3")
With .Resize(x)
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
End With
With .Resize(x, UBound(b, 2))
.Value = b
.Borders.LineStyle = xlNone
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
End With
End With
End With
End If
Next
Set ws = Nothing
Set sDic = Nothing
End Sub
Display More