how to find hyphen from 12-12-123

dummies

New Member
Joined
Jul 10, 2020
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
hello friends
help me with vba code to
1.find hyphen (12-12-123)
2. split into 3groups
3.check if they are numeric ( group)
4. find the length of group

thank you very much
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Does it have to be with vba?

Can you show us how the result(s) should be shown?

Better still, can you show us a variety of input data (it sounds like sometimes it might not all be numeric), preferably with XL2BB so we can copy/paste to test with and include the expected results?
 
Upvote 0
I think you have similar interest as this

 
Upvote 0
Does it have to be with vba?

Can you show us how the result(s) should be shown?

Better still, can you show us a variety of input data (it sounds like sometimes it might not all be numeric), preferably with XL2BB so we can copy/paste to test with and include the expected results?
thank you for the response.
yes it is. Actually i have a table which has product name and product no. so i want to check if product no contain product no.
VBA Code:
<table style="width:100%">
  <tr>
    <th>prodeuctName</th>
    <th>productNo</th>
    
  </tr>
  <tr>
    <td>s12-12-123</td>
    <td>12-12-123</td>
    
  </tr>
  <tr>
    <td>s12-12-124</td>
    <td>12-12-124</td>
  
  </tr>
</table>
 
Upvote 0
المصنف1
AB
112-12-123-AA
212TRUE
312TRUE
4123TRUE
5AAFALSE
ورقة1
Cell Formulas
RangeFormula
A2:A5A2=IFERROR(TRIM(MID($A$1,FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1)),FIND("|",SUBSTITUTE(" "&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-1)),"")
B2:B5B2=IFERROR(ISNUMBER(NUMBERVALUE(TRIM(MID($A$1,FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1)),FIND("|",SUBSTITUTE(" "&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-1)))),"")

copy.png
 
Last edited:
Upvote 0
Unfortunately, as you can see, you cannot show sample data like that.

Also, this does not make sense to me:
sorry i mean to say, check if column (product no) contains product name.
productNo=12-12-123
productName=s12-12-123
 
Upvote 0
المصنف1
AB
112-12-123-AA
212TRUE
312TRUE
4123TRUE
5AAFALSE
ورقة1
Cell Formulas
RangeFormula
A2:A5A2=IFERROR(TRIM(MID($A$1,FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1)),FIND("|",SUBSTITUTE(" "&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-1)),"")
B2:B5B2=IFERROR(ISNUMBER(NUMBERVALUE(TRIM(MID($A$1,FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1)),FIND("|",SUBSTITUTE(" "&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-FIND("|",SUBSTITUTE("-"&$A$1&"-","-","|",ROW()-ROW($A$2)+1))-1)))),"")

View attachment 27558
This is similar to what I really what to do.if possible could you help me to do it in vba. Thank you very much.
 
Upvote 0
check if column (product no) contains product name.
I'm guessing you actually mean that the other way around. That is "check if product name contains product no."
If so, you could try this with a copy of your data.

VBA Code:
Sub NumberInName()
  Dim a As Variant, b As Variant
  Dim i As Long
  
  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    b(i, 1) = IIf(InStr(1, a(i, 1), a(i, 2), 1) > 0, "Yes", "No")
  Next i
  Range("C2").Resize(UBound(b)).Value = b
End Sub

Here is my sample data and results

dummies.xlsm
ABC
1product nameproduct no.Product no. in product name?
2s12-12-12312-12-123Yes
3s12-12-12415-19-195No
Sheet1
 
Upvote 0
Solution
I'm guessing you actually mean that the other way around. That is "check if product name contains product no."
If so, you could try this with a copy of your data.

VBA Code:
Sub NumberInName()
  Dim a As Variant, b As Variant
  Dim i As Long

  a = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    b(i, 1) = IIf(InStr(1, a(i, 1), a(i, 2), 1) > 0, "Yes", "No")
  Next i
  Range("C2").Resize(UBound(b)).Value = b
End Sub

Here is my sample data and results

dummies.xlsm
ABC
1product nameproduct no.Product no. in product name?
2s12-12-12312-12-123Yes
3s12-12-12415-19-195No
Sheet1
thank you so much.
what if , if i have checkbox next to productName and if i check the checkbox(C5) then value in A5 is displayed in textbox next to checkbox?
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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