Add elements for adjacent cells by insert column based on multiple characters

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
651
Office Version
  1. 2019
Hello
I'm not sure if could be by macro , but what I want if the item in column B contains R & number like this 700R16 or 195R15C or 29.5R25** VSDL as bold after R letter then should add element (TIRES) in adjacent cell for column C and if the item in column B contains / then the element in column C should be TIRES and if the item in column B contains × & - then the element in column C should be TIRES like this 28×9-15 LO as bold, if the item in column B contains number & letter A then the element in column C should be BATTERY like this 70A R OR 74A L or 100A as bold, if if the item in column B contains number & × & number & L then the element in column C should be OIL like this PP MEG 24KG 4×5L or CYU MEG 4×4L as bold .

[
CC1.xlsm
ABCDE
1ITEMBATCHQTYPRICETOTAL
21235/60R184.00LYD 425.00LYD 1,700.00
32750R16 L502.00LYD 400.00LYD 800.00
43700R167.00LYD 800.00LYD 5,600.00
54215/65R164.00LYD 355.00LYD 1,420.00
65265/70R165.00LYD 550.00LYD 2,750.00
7629.5R25** VSDL24.00LYD 385.00LYD 9,240.00
87265/60R184.00LYD 540.00LYD 2,160.00
98225/75R151.00LYD 340.00LYD 340.00
109275/50R214.00LYD 780.00LYD 3,120.00
1110265/65R175.00LYD 700.00LYD 3,500.00
1211195R15C5.00LYD 600.00LYD 3,000.00
131218.4/15-30-204.00LYD 310.00LYD 1,240.00
141328×9-15 LO2.00LYD 580.00LYD 1,160.00
151470A R10.00LYD 405.00LYD 4,050.00
161560A10.00LYD 335.00LYD 3,350.00
171690A6.00LYD 470.00LYD 2,820.00
181774A L4.00LYD 310.00LYD 1,240.00
1918100A3.00LYD 490.00LYD 1,470.00
2019150A4.00LYD 650.00LYD 2,600.00
2120120A2.00LYD 565.00LYD 1,130.00
222123.5R25 18.4-301.00LYD 385.00LYD 385.00
2322PP MEG 24KG 4×5L21.00LYD 40.00LYD 840.00
2423CYU MEG 4×4L24.00LYD 50.00LYD 1,200.00
25TOTALLYD 55,115.00
combined
Cell Formulas
RangeFormula
E2:E24E2=C2*D2
E25E25=SUM(E2:E24)


result

CC1.xlsm
ABCDEF
1ITEMBATCHGROUPQTYPRICETOTAL
21235/60R18TIRES4.00LYD 425.00LYD 1,700.00
32750R16 L50TIRES2.00LYD 400.00LYD 800.00
43700R16TIRES7.00LYD 800.00LYD 5,600.00
54215/65R16TIRES4.00LYD 355.00LYD 1,420.00
65265/70R16TIRES5.00LYD 550.00LYD 2,750.00
7629.5R25** VSDLTIRES24.00LYD 385.00LYD 9,240.00
87265/60R18TIRES4.00LYD 540.00LYD 2,160.00
98225/75R15TIRES1.00LYD 340.00LYD 340.00
109275/50R21TIRES4.00LYD 780.00LYD 3,120.00
1110265/65R17TIRES5.00LYD 700.00LYD 3,500.00
1211195R15CTIRES5.00LYD 600.00LYD 3,000.00
131218.4/15-30-20TIRES4.00LYD 310.00LYD 1,240.00
141328×9-15 LOTIRES2.00LYD 580.00LYD 1,160.00
151470A RBATTERY10.00LYD 405.00LYD 4,050.00
161560ABATTERY10.00LYD 335.00LYD 3,350.00
171690ABATTERY6.00LYD 470.00LYD 2,820.00
181774A LBATTERY4.00LYD 310.00LYD 1,240.00
1918100ABATTERY3.00LYD 490.00LYD 1,470.00
2019150ABATTERY4.00LYD 650.00LYD 2,600.00
2120120ABATTERY2.00LYD 565.00LYD 1,130.00
222123.5R25 18.4-30TIRES1.00LYD 385.00LYD 385.00
2322PP MEG 24KG 4×5LOIL21.00LYD 40.00LYD 840.00
2423CYU MEG 4×4LOIL24.00LYD 50.00LYD 1,200.00
25TOTALLYD 55,115.00
EXPECTED
Cell Formulas
RangeFormula
F2:F24F2=D2*E2
F25F25=SUM(F2:F24)

should be clear data in second sheet from row 2 before bring data . if it's impossible by macro or any suggestion to make easy things I accept that or formula
thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
terima kasih aku akan menunggumu sampai besok.
tidak usah buru-buru .:)
Sorry for waiting so long @abdo meghari

i have 2 option u can use with formula or VBA

a. Formula
u can manually adding one column and Copy this Formula on Column C (See The Picture Below)

1702513995864.png


This the Formula
Excel Formula:
=LET(

OIL,
IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("×",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("×",B2)-1,1))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("×",B2)+1,1))),IFERROR(IF(MID(B2,SEARCH("×",B2)+2,1)="L",TRUE,FALSE),FALSE))=TRUE,TRUE,FALSE),


BATT,
IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("A",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("A",B2)-1,1))))=TRUE,TRUE,FALSE),


WHILE,
IF(OR(IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("R",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("R",B2)+1,1))))=TRUE,TRUE,FALSE),IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("×",B2))),ISNUMBER(NUMBERVALUE(SEARCH("-",B2))))=TRUE,TRUE,FALSE),ISNUMBER(NUMBERVALUE(SEARCH("/",B2))))=TRUE,TRUE,FALSE),

IF(OIL=TRUE,"OIL",IF(BATT=TRUE,"Battry",IF(WHILE=TRUE,"While",""))))


b. VBA

VBA Code:
Sub IFANDOR()
Application.ScreenUpdating = False


    ActiveSheet.Select
    Columns("C:C").Insert Shift:=xlToRight  ' U can Change Column
    
    Range("C1").Formula = "GROUP"  'Name of Header Column C
    
    'Formula
    Range("C2").FormulaR1C1 = _
        "=LET(" & Chr(10) & "" & Chr(10) & "OIL," & Chr(10) & "IF(AND(ISNUMBER(NUMBERVALUE(SEARCH(""×"",RC[-1]))),ISNUMBER(NUMBERVALUE(MID(RC[-1],SEARCH(""×"",RC[-1])-1,1))),ISNUMBER(NUMBERVALUE(MID(RC[-1],SEARCH(""×"",RC[-1])+1,1))),IFERROR(IF(MID(RC[-1],SEARCH(""×"",RC[-1])+2,1)=""L"",TRUE,FALSE),FALSE))=TRUE,TRUE,FALSE)," & Chr(10) & "" & Chr(10) & "" & Chr(10) & "BATT," & Chr(10) & "IF(AND(ISNUMBER(NUMBERVALUE(SEARCH(""A"",RC[-1]))),ISNUMBER(NUMBERVALUE(MID(RC[-1],SE" & _
        "ARCH(""A"",RC[-1])-1,1))))=TRUE,TRUE,FALSE)," & Chr(10) & "" & Chr(10) & "" & Chr(10) & "WHILE," & Chr(10) & "IF(OR(IF(AND(ISNUMBER(NUMBERVALUE(SEARCH(""R"",RC[-1]))),ISNUMBER(NUMBERVALUE(MID(RC[-1],SEARCH(""R"",RC[-1])+1,1))))=TRUE,TRUE,FALSE),IF(AND(ISNUMBER(NUMBERVALUE(SEARCH(""×"",RC[-1]))),ISNUMBER(NUMBERVALUE(SEARCH(""-"",RC[-1]))))=TRUE,TRUE,FALSE),ISNUMBER(NUMBERVALUE(SEARCH(""/"",RC[-1]))))=TRUE,TRUE,FALSE)," & Chr(10) & "" & Chr(10) & "IF" & _
        "(OIL=TRUE,""OIL"",IF(BATT=TRUE,""Battry"",IF(WHILE=TRUE,""While"",""""))))" & _
        ""
    
    'Auto Copy to Last Row
    Range("C2").AutoFill Destination:=Range("C2:C" & Range("B" & Rows.Count).End(xlUp).Row)
    Range(Selection, Selection.End(xlDown)).Select
    
    
    Application.ScreenUpdating = True
    MsgBox "Done"
    
    
End Sub


*I hope this helps your problem, If there’s any unclear information please let me know :)
 
Upvote 0
thanks :)
just question , your solution deals with Office Version 2010 because I work for another laptop contains 2010 version ?
because shows error
CC1.xlsm
ABCDEF
1ITEMBATCHGROUPQTYPRICETOTAL
21235/60R18#NAME?4.00LYD 425.00LYD 1,700.00
32750R16 L50#NAME?2.00LYD 400.00LYD 800.00
43700R16#NAME?7.00LYD 800.00LYD 5,600.00
54215/65R16#NAME?4.00LYD 355.00LYD 1,420.00
65265/70R16#NAME?5.00LYD 550.00LYD 2,750.00
7629.5R25** VSDL#NAME?24.00LYD 385.00LYD 9,240.00
87265/60R18#NAME?4.00LYD 540.00LYD 2,160.00
98225/75R15#NAME?1.00LYD 340.00LYD 340.00
109275/50R21#NAME?4.00LYD 780.00LYD 3,120.00
1110265/65R17#NAME?5.00LYD 700.00LYD 3,500.00
1211195R15C#NAME?5.00LYD 600.00LYD 3,000.00
131218.4/15-30-20#NAME?4.00LYD 310.00LYD 1,240.00
141328×9-15 LO#NAME?2.00LYD 580.00LYD 1,160.00
151470A R#NAME?10.00LYD 405.00LYD 4,050.00
161560A#NAME?10.00LYD 335.00LYD 3,350.00
171690A#NAME?6.00LYD 470.00LYD 2,820.00
181774A L#NAME?4.00LYD 310.00LYD 1,240.00
1918100A#NAME?3.00LYD 490.00LYD 1,470.00
2019150A#NAME?4.00LYD 650.00LYD 2,600.00
2120120A#NAME?2.00LYD 565.00LYD 1,130.00
222123.5R25 18.4-30#NAME?1.00LYD 385.00LYD 385.00
2322PP MEG 24KG 4×5L#NAME?21.00LYD 40.00LYD 840.00
2423CYU MEG 4×4L#NAME?24.00LYD 50.00LYD 1,200.00
25TOTALLYD 55,115.00
combined
Cell Formulas
RangeFormula
C2:C24C2=LET( OIL, IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("×",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("×",B2)-1,1))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("×",B2)+1,1))),IFERROR(IF(MID(B2,SEARCH("×",B2)+2,1)="L",TRUE,FALSE),FALSE))=TRUE,TRUE,FALSE), BATT, IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("A",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("A",B2)-1,1))))=TRUE,TRUE,FALSE), WHILE, IF(OR(IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("R",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("R",B2)+1,1))))=TRUE,TRUE,FALSE),IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("×",B2))),ISNUMBER(NUMBERVALUE(SEARCH("-",B2))))=TRUE,TRUE,FALSE),ISNUMBER(NUMBERVALUE(SEARCH("/",B2))))=TRUE,TRUE,FALSE), IF(OIL=TRUE,"OIL",IF(BATT=TRUE,"Battry",IF(WHILE=TRUE,"While",""))))
F2:F24F2=D2*E2
F25F25=SUM(F2:F24)

if it's not then I should test it for version 2019 at work but not today .
 
Upvote 0
thanks :)
just question , your solution deals with Office Version 2010 because I work for another laptop contains 2010 version ?
because shows error
CC1.xlsm
ABCDEF
1ITEMBATCHGROUPQTYPRICETOTAL
21235/60R18#NAME?4.00LYD 425.00LYD 1,700.00
32750R16 L50#NAME?2.00LYD 400.00LYD 800.00
43700R16#NAME?7.00LYD 800.00LYD 5,600.00
54215/65R16#NAME?4.00LYD 355.00LYD 1,420.00
65265/70R16#NAME?5.00LYD 550.00LYD 2,750.00
7629.5R25** VSDL#NAME?24.00LYD 385.00LYD 9,240.00
87265/60R18#NAME?4.00LYD 540.00LYD 2,160.00
98225/75R15#NAME?1.00LYD 340.00LYD 340.00
109275/50R21#NAME?4.00LYD 780.00LYD 3,120.00
1110265/65R17#NAME?5.00LYD 700.00LYD 3,500.00
1211195R15C#NAME?5.00LYD 600.00LYD 3,000.00
131218.4/15-30-20#NAME?4.00LYD 310.00LYD 1,240.00
141328×9-15 LO#NAME?2.00LYD 580.00LYD 1,160.00
151470A R#NAME?10.00LYD 405.00LYD 4,050.00
161560A#NAME?10.00LYD 335.00LYD 3,350.00
171690A#NAME?6.00LYD 470.00LYD 2,820.00
181774A L#NAME?4.00LYD 310.00LYD 1,240.00
1918100A#NAME?3.00LYD 490.00LYD 1,470.00
2019150A#NAME?4.00LYD 650.00LYD 2,600.00
2120120A#NAME?2.00LYD 565.00LYD 1,130.00
222123.5R25 18.4-30#NAME?1.00LYD 385.00LYD 385.00
2322PP MEG 24KG 4×5L#NAME?21.00LYD 40.00LYD 840.00
2423CYU MEG 4×4L#NAME?24.00LYD 50.00LYD 1,200.00
25TOTALLYD 55,115.00
combined
Cell Formulas
RangeFormula
C2:C24C2=LET( OIL, IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("×",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("×",B2)-1,1))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("×",B2)+1,1))),IFERROR(IF(MID(B2,SEARCH("×",B2)+2,1)="L",TRUE,FALSE),FALSE))=TRUE,TRUE,FALSE), BATT, IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("A",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("A",B2)-1,1))))=TRUE,TRUE,FALSE), WHILE, IF(OR(IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("R",B2))),ISNUMBER(NUMBERVALUE(MID(B2,SEARCH("R",B2)+1,1))))=TRUE,TRUE,FALSE),IF(AND(ISNUMBER(NUMBERVALUE(SEARCH("×",B2))),ISNUMBER(NUMBERVALUE(SEARCH("-",B2))))=TRUE,TRUE,FALSE),ISNUMBER(NUMBERVALUE(SEARCH("/",B2))))=TRUE,TRUE,FALSE), IF(OIL=TRUE,"OIL",IF(BATT=TRUE,"Battry",IF(WHILE=TRUE,"While",""))))
F2:F24F2=D2*E2
F25F25=SUM(F2:F24)

if it's not then I should test it for version 2019 at work but not today .
my bad, ok try with Excel Ver.2019, and if still eror i will convert the formula to manually
 
Upvote 0
That formula will still error in 2019 as only 2012 & 365 have the LET function
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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