Hello everyone
I have a column of raw data with some items (Column B) and I already have other items in Column K which I need to search partially for them in Column B and sum the total for the suitable item
The attachment will be better for clarification. The desired output in Column L
Thanks advanced for help
Posted here: https://www.excelforum.com/excel-progra ... -text.html" onclick="window.open(this.href);return false;
Sum total by partial text
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Sum total by partial text
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78569
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Sum total by partial text
What do you mean? ..
-
- Administrator
- Posts: 78569
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Sum total by partial text
Currently, column A and column K use an inconsistent mix of "-" and "_". You should make that consistent first. Next, get rid of the extra "14" in column A (and presumably other things like that in the real data).
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Sum total by partial text
I need to deal with the data as it is as real data consists of thousands of rows and the process of cleaning up will take too much time.
Can regular expressions do such task .. I mean to depend on patterns?
Can regular expressions do such task .. I mean to depend on patterns?
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Sum total by partial text
I got it solved by Karedog's code which depends on regular expressions as I expect.
Thank you very much Mr. Hans
Code: Select all
Sub Test()
Dim a, b, i As Long, j As Long, v
With Sheets("Sheet1")
a = .Range("B4:G10").Value
b = .Range("K8:K11").Value
With CreateObject("VBScript.RegExp")
.IgnoreCase = True
For i = 1 To UBound(b, 1)
v = Split(b(i, 1), "_")
b(i, 1) = 0
.Pattern = ".*" & v(0) & ".*[-_].*" & v(1) & ".*"
For j = 1 To UBound(a, 1)
If .Test(a(j, 1)) Then b(i, 1) = b(i, 1) + a(j, 6)
Next j
Next i
End With
.Range("N8").Resize(UBound(b, 1), UBound(b, 2)).Value = b
End With
End Sub