Add item for first location with space based on matching helper column

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
606
Office Version
  1. 2019
Hello,
I would match column B with column H then should add item from column G to the first location with make space in column C for each cell
before
MR.xlsm
BCDEFGH
1MARKBRANDQTYMARK SHORTMARK
2BRIDGESTONE1200R20 G580 JAP200BSBRIDGESTONE
3FIRESTONE1200R20 G580 JAP120FSRFIRESTONE
4DAYTON1200R20 G580 JAP300DATDAYTON
5BRIDGESTONE1200R20 G580 THI230GRDGOODRIDE
6FIRESTONE1200R20 FSR4000 THI120KOHMKOUHMO
7DAYTON1200R20 D50A THI110
8GOODRIDE1200R20 GR42313
9KOUHMO1200R20 KT1214
10GOODRIDE1400R20 VSJ15
MARK


after

MR.xlsm
ABCDEFGH
1MARKBRANDQTYMARK SHORTMARK
2BRIDGESTONEBS 1200R20 G580 JAP200BSBRIDGESTONE
3FIRESTONEFSR 1200R20 G580 JAP120FSRFIRESTONE
4DAYTONDAT 1200R20 G580 JAP300DATDAYTON
5BRIDGESTONEBS 1200R20 G580 THI230GRDGOODRIDE
6FIRESTONEFSR 1200R20 FSR4000 THI120KOHMKOUHMO
7DAYTONDAT 1200R20 D50A THI110
8GOODRIDEGRD 1200R20 GR42313
9KOUHMOKOHM 1200R20 KT1214
10GOODRIDEGRD 1400R20 VSJ15
11
MARK

every time I add new data for both ranges.
when run the macro every time should search for items are added in first location in column C with matched column H if there are existed then don't add , just search for missed for any item.
thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try below code:

VBA Code:
Option Explicit
Sub AddMarkShort()
Dim i&, rng, short, sp
Dim dic As Object, key
Set dic = CreateObject("scripting.dictionary")
rng = Range("B2:C" & Cells(Rows.Count, "B").End(xlUp).Row).Value
short = Range("G2:H" & Cells(Rows.Count, "G").End(xlUp).Row).Value
For i = 1 To UBound(short)
    dic.Add short(i, 1), short(i, 2)
Next
For i = 1 To UBound(rng)
    sp = Split(rng(i, 2), " ")
    If Not dic.exists(sp(0)) Then
        For Each key In dic.keys
            If dic(key) = rng(i, 1) Then
                rng(i, 2) = key & " " & rng(i, 2)
                Exit For
            End If
        Next
    End If
Next
Range("B2:C" & Cells(Rows.Count, "B").End(xlUp).Row).Value = rng
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,630
Messages
6,173,457
Members
452,516
Latest member
archcalx

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