Advertisement
phamchin

D4

Aug 23rd, 2022
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Option Explicit
  2.  
  3.  
  4. Sub compact()
  5. Dim wsdt As Worksheet, wsmt As Worksheet
  6. Dim raw_data As Range, master_bom As Range, index As Range
  7.  
  8. Dim a As Long, b As Long, x As Long, y As Long
  9. Dim k As Long, i As Long, j As Long
  10.  
  11. Set raw_data = Application.InputBox(prompt:="Select your range", _
  12. Title:="Input data", _
  13. Type:=8)
  14.  
  15. Set master_bom = Application.InputBox(prompt:="Select your master bom range", _
  16. Title:="Input data", _
  17. Type:=8)
  18.  
  19. x = raw_data.Rows.Count
  20. y = raw_data.Columns.Count
  21.  
  22. a = master_bom.Rows.Count
  23. b = master_bom.Columns.Count
  24.  
  25. Set wsdt = raw_data.Worksheet
  26. Set wsmt = master_bom.Worksheet
  27.  
  28. For i = 1 To y
  29. For j = 1 To x
  30. With Worksheets(wsmt.Name)
  31. Set index = master_bom.Find( _
  32. What:=raw_data(j, i), _
  33. LookIn:=xlValues)
  34. raw_data(j, i).Offset(0, -1) = master_bom(index.row, 1)
  35. 'Debug.Print (raw_data(j, i) & "Found in row" & index.row)
  36. End With
  37. Next j
  38. Next i
  39.  
  40.  
  41.  
  42. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement