Match two sheets with another based on column and equal space

tubrak

Board Regular
Joined
May 30, 2021
Messages
218
Office Version
  1. 2019
Platform
  1. Windows
hi
I would arrange data in column B into sheets first,second based on matching with sheet BASIC into column A . the space should be one time among the items into column B in sheet first,second based on three columns B,C,D into sheet BASIC . the columns B,C,D into sheet BASIC is each item into column B in sheets first ,second . if can do by macro it will be a great because my data increases with overtime .
first
userform.xlsm
AB
1BATCHITEM
2LK1-100TR 12-200M45 MM123H K/L
3LK1-101TR 200M45 LK H K/L
4LK1-102TTR 12200S45 MN 123
5LK1-103TR 1425/148V MN 123H K/L
6LK1-104TR 200M45 MM 123H K/L
7LK1-105TR 2.5M100 * 123H K/L
8LK1-106TR 2.5M100**123H K/L
FIRST


second
userform.xlsm
AB
1BATCHITEM
2LK1-100TR 12-200 M45 MM 123H K/L
3LK1-101TR 200M45 LK H K/L
4LK1-102TTR 12200S45 MN 123
5LK1-103TR 1425 / 148V MN 123H K/L
6LK1-104TR 200M45 MM 123H K/L
7LK1-105TR 2.5 M100* 123H K/L
8LK1-106TR 2.5M100** 123H K/L
9
SECOND


basic
userform.xlsm
ABCD
1BATCHFIRST PARTSECOND PARTTHIRD PART
2LK1-100TR 12-200M45 MM 123H K/L
3LK1-101TR 200M45LK H K/L
4LK1-102TTR 12200S45MN123
5LK1-103TR 1425/148VMN 123H K/L
6LK1-104TR 200M45 MM123H K/L
7LK1-105TR 2.5M100*123H K/L
8LK1-106TR 2.5M100** 123H K/L
BASIC



result
first
userform.xlsm
AB
1BATCHITEM
2LK1-100TR 12-200M45 MM 123H K/L
3LK1-101TR 200M45 LK H K/L
4LK1-102TTR 12200S45 MN 123
5LK1-103TR 1425/148V MN 123H K/L
6LK1-104TR 200M45 MM 123H K/L
7LK1-105TR 2.5M100* 123H K/L
8LK1-106TR 2.5M100** 123H K/L
FIRST



second
userform.xlsm
AB
1BATCHITEM
2LK1-100TR 12-200M45 MM 123H K/L
3LK1-101TR 200M45 LK H K/L
4LK1-102TTR 12200S45 MN 123
5LK1-103TR 1425/148V MN 123H K/L
6LK1-104TR 200M45 MM 123H K/L
7LK1-105TR 2.5M100* 123H K/L
8LK1-106TR 2.5M100** 123H K/L
SECOND
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi, please check below. We can use excel formula to get the result.

Cell Formulas
RangeFormula
B2:B8B2=CONCATENATE(VLOOKUP(A2,basic!$A$1:$D$8,2,0)," ", VLOOKUP(A2,basic!$A$1:$D$8,3,0), " ", VLOOKUP(A2,basic!$A$1:$D$8,4,0))



Cell Formulas
RangeFormula
B2:B8B2=CONCATENATE(VLOOKUP(A2,basic!$A$1:$D$8,2,0)," ", VLOOKUP(A2,basic!$A$1:$D$8,3,0), " ", VLOOKUP(A2,basic!$A$1:$D$8,4,0))
 
Upvote 0
despite of it I would by vba, but thanks for choice the formula.
based on your formula doesn't create one space with comparison my data
some items has two spaces befor or after it , may you check it,please
 
Upvote 0
Hi, Yes we can create VBA for this.

Meanwhile using trim can remove the spaces.

Excel Formula:
=CONCATENATE(TRIM(VLOOKUP(A2,basic!$A$1:$D$8,2,0))," ", TRIM(VLOOKUP(A2,basic!$A$1:$D$8,3,0)), " ", TRIM(VLOOKUP(A2,basic!$A$1:$D$8,4,0)))
 
Upvote 0
thanks for your solution ;)
I will wait for another body to provide me by code .if I don't get it. so I close the thread and accept your answering.
 
Upvote 0
Hi,

Please check below code. The code will generate output in Sheet "first"

VBA Code:
Option Explicit

Sub fillData()
Dim totRows As Integer, rowno As Integer
Dim foundcell As Range

totRows = Sheets("first").Cells(Rows.Count, 1).End(xlUp).Row

For rowno = 2 To totRows
    Set foundcell = Sheets("basic").Cells.Find(what:=Sheets("first").Range("A" & rowno), After:=Sheets("basic").Cells(1, 1), _
    LookIn:=xlValues, lookat:=xlPart, searchOrder:=xlByRows, _
    searchdirection:=xlNext, MatchCase:=False, searchformat:=False)
    
    If Not foundcell Is Nothing Then
        Sheets("first").Range("B" & rowno) = Trim(Sheets("basic").Range("B" & foundcell.Row)) & " " & _
        Trim(Sheets("basic").Range("C" & foundcell.Row)) & " " & _
        Trim(Sheets("basic").Range("D" & foundcell.Row))
    End If
Next
End Sub
 
Upvote 0
again thanks and this is great.
do you have any idea to make array like this rr=array(first,second) to implement th code for two sheets instead of repeate the macro again for another sheet ?
I believe the code can be shortened by using array , but I have no idea.
 
Upvote 0
Hi,

Use below:

VBA Code:
Sub fillData()
Dim totRows As Integer, rowno As Integer
Dim sheetnum As Integer
Dim foundcell As Range
Dim ws(1 To 2) As String

ws(1) = "first"
ws(2) = "second"

For sheetnum = 1 To 2
    For rowno = 2 To Sheets(ws(sheetnum)).Cells(Rows.Count, 1).End(xlUp).Row
        Set foundcell = Sheets("basic").Cells.Find(what:=Sheets(ws(sheetnum)).Range("A" & rowno), After:=Sheets("basic").Cells(1, 1), _
        LookIn:=xlValues, lookat:=xlPart, searchOrder:=xlByRows, _
        searchdirection:=xlNext, MatchCase:=False, searchformat:=False)
       
        If Not foundcell Is Nothing Then
            With Sheets("basic")
                Sheets(ws(sheetnum)).Range("B" & rowno) = Trim(.Range("B" & foundcell.Row)) & " " & _
                Trim(.Range("C" & foundcell.Row)) & " " & _
                Trim(.Range("D" & foundcell.Row))
            End With
        End If
    Next
Next
End Sub
 
Upvote 0
Solution
I appreciate for your effort and time.
many thanks for all theses answers :)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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