Finding text after a value in a cell, then copying to another cell

wnwrd

New Member
Joined
Feb 15, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Good morning!

I'm new to VBA, so I'm a little stuck. I'm trying to copy the text after "brand=" in column AU until "," as well as the text after "model=", then paste it into column E after "Default Category/Lexan Polycarbonate Motorsport Windows & Kits" with a "/" between the two strings.

I have managed to create code to find the relevant cell and select text after "brand=", but I am unsure how to proceed from here. Here's my code so far:
VBA Code:
Sub findmakemodel()
    If ActiveCell.Value = "Default Category/Lexan Polycarbonate Motorsport Windows & Kits" Then
        ActiveCell.Offset(0, 42).Select
    End If
    If InStr(1, (ActiveCell.Value), "brand=") > 0 Then

If anyone could point me in the right direction it would be massively appreciated.
 

Attachments

  • Screenshot 2023-02-15 at 09.24.17.png
    Screenshot 2023-02-15 at 09.24.17.png
    98.5 KB · Views: 10

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
VBA Code:
Sub findmakemodel()
Dim K$, L1$, L2$, F1&, F2&
    If ActiveCell.Value = "Default Category/Lexan Polycarbonate Motorsport Windows & Kits" Then
    K = ActiveCell.Offset(0, 42) '.Select
    F1 = InStr(1, K, "brand=")
    If F1 > 0 Then L1 = "/" & Mid(K, F1 + Len("brand="), InStr(F1, K, ",") - F1 - Len("brand="))
    F2 = InStr(1, K, "model=")
    If F2 > 0 Then L2 = "/" & Mid(K, F2 + Len("model="), InStr(F2, K, ",") - F2 - Len("model="))
    
    ActiveCell.Value = ActiveCell.Value & L1 & L2
    End If
End Sub
 
Upvote 1
Solution
Try
VBA Code:
Sub findmakemodel()
Dim K$, L1$, L2$, F1&, F2&
    If ActiveCell.Value = "Default Category/Lexan Polycarbonate Motorsport Windows & Kits" Then
    K = ActiveCell.Offset(0, 42) '.Select
    F1 = InStr(1, K, "brand=")
    If F1 > 0 Then L1 = "/" & Mid(K, F1 + Len("brand="), InStr(F1, K, ",") - F1 - Len("brand="))
    F2 = InStr(1, K, "model=")
    If F2 > 0 Then L2 = "/" & Mid(K, F2 + Len("model="), InStr(F2, K, ",") - F2 - Len("model="))
   
    ActiveCell.Value = ActiveCell.Value & L1 & L2
    End If
End Sub
That's made things much easier, thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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