VBA Fill missing information

notrealname

New Member
Joined
Nov 24, 2011
Messages
14
Hi,
Searching for help to automatically fill missing information in column E where cells in column D match:
[TABLE="width: 557"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Control Number[/TD]
[TD]Control[/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD]Critical Spares for Girth Gear [/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071879[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD]Perform maintenance tasks to detect misalignment and deficient grease[/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]50071878[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
if you created a table of number and control on a separate sheet, then you could use vba to run down the list where missing and insert the relevant information on blanks
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG03Apr50
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
   .Add Dn.Value, Array(Dn, Dn.Offset(, 1).Value)
[COLOR="Navy"]Else[/COLOR]
    Q = .Item(Dn.Value)
        [COLOR="Navy"]Set[/COLOR] Q(0) = Union(Q(0), Dn)
        Q(1) = Q(1) & Dn.Offset(, 1).Value
    .Item(Dn.Value) = Q
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]Dim[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
    .Item(K)(0).Offset(, 1).Value = Trim(.Item(K)(1))
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
MickG appears to be offline, but try

Code:
Sub MG03Apr50()
Dim Rng As Range, Dn As Range, n As Long, Q As Variant
Set Rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not .Exists(Dn.Value) Then
   .Add Dn.Value, Array(Dn, Dn.Offset(, 1).Value)
Else
    Q = .Item(Dn.Value)
        Set Q(0) = Union(Q(0), Dn)
        Q(1) = Q(1) & Dn.Offset(, 1).Value
    .Item(Dn.Value) = Q
End If
Next
Dim K As Variant
For Each K In .keys
    .Item(K)(0).Offset(, 1).Value = Trim(.Item(K)(1))
Next K
[color=red]End With[/color]
End Sub
 
Upvote 0
Thanks Michael !!
I've made that copying error once or twice lately. I think a slight rethink is required !!!
Regrds Mick
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top