VBA FIND text question

hitbid

Board Regular
Joined
Jan 21, 2016
Messages
114
I am trying to return a name from a long line of text.

Below is a sample line:

Shipdate: 04/03/18 Stk Br # 1 Writer: Mark Smith Tax Jurisdiction: 1

Every line is edited the same every time, with a shipdate, writer, and tax jurisdiction. I am trying to extract the name of the writer in every line, which can be different.

Here I want to extract Mark Smith and paste it to a new sheet.

I understand the FIND function as a formula, but it isn't being as intuitive to me in VBA.

I had started to write something like this, but I am lost and not sure how to solve for this.
Code:
Sub Writer()Dim Writ As Variant
    FindIVZ
Cells.Find(What:="Writer:*", After:=ActiveCell, LookIn:=xlFormulas, LookAt _        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Writ = Application.WorksheetFunction.Find(":", "Writer:*")

This is all wrong I know. Any ideas?
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I think I figured it out.

I used this and it comes back with the name. Maybe not the absolute best code, but it works.
Code:
Sub Writer()Dim Writ As Double
Dim Tax As Double
Dim Wr As Variant


    FindIVZ
    
    Cells.Find(What:="Writer:*", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Writ = InStr(ActiveCell, "Writer:")
    Tax = InStr(ActiveCell, "Tax Jur")
    Wr = Mid(ActiveCell, Writ + 8, Tax - (Writ + 8))
    
    MsgBox Wr


End Sub
 
Upvote 0
Maybe not the absolute best code, but it works.
If it works, that's fine. :)
However, if you are interested, here is another way. (I gather from your code, we don't know what column the text is in each time?)
Code:
Sub Find_Writer()
  Dim WriterCell As Range
  
  Set WriterCell = Cells.Find(What:="Writer:", LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
  If Not WriterCell Is Nothing Then
    MsgBox Trim(Split(Split(WriterCell.Value, "Writer:")(1), "Tax Jurisdiction:")(0))
  End If
End Sub
 
Upvote 0
Interesting, I have not used the split function, but reading up on it I am realizing I should, thank you.

Your's worked. So I tried to finish the subroutine by pasting in the final four lines, but getting an error on the last line, where I am trying to have the active cell value match the range value variable you just gave me.

Code:
    Sheets("Totals").Select    Range("B900000").End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = WriterCell.Value
 
Upvote 0
Interesting, I have not used the split function, but reading up on it I am realizing I should, thank you.

Your's worked. So I tried to finish the subroutine by pasting in the final four lines, but getting an error on the last line, where I am trying to have the active cell value match the range value variable you just gave me.

Code:
    Sheets("Totals").Select    Range("B900000").End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = WriterCell.Value
1. What is the full code?

2. What is the full error message

3. What line is highlighted if you click debug when you get the error?
 
Upvote 0
or with a formula
Code:
=MID(A2,FIND("Writer:",A2,1)+8,FIND(" Tax Jurisdiction",A2)-FIND("Writer:",A2,1)-8)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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