Trying find first word in a cell to use in my code

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
I`ve set a function code up to find the correct value.
Then tried to add it to the qry code it says "Argument not optional
Please let me know why Thanks in advance

VBA Code:
Private Sub Decals_Type_Click()

Dim cbo         As ComboBox
Dim wsSource    As Worksheet
Dim wsDest      As Worksheet
Dim Addme       As Range, Rng As Range
Dim iRow        As Long
Dim qry         As String
Dim val         As String
Dim BodyType    As String

Set wsSource = ThisWorkbook.Sheets("Part_Group_Items_ List")

Set wsDest = ThisWorkbook.Sheets("Job Card Master")

With wsDest

iRow = Selection.Row

Set Addme = wsDest.Range("A" & iRow)

Set cbo = Decals_Type

If cbo.Value = "Tippa" Then

Set BodyType = FindTippa

qry = "SELECT * FROM [Decals] " & _
    " WHERE [DecalType]='" & BodyType.Text & "'"

        iRow = iRow

        Dim rs As Object: Set rs = OpenConAndGetRS(qry)
        If Not (rs.BOF Or rs.EOF) Then
            Do While Not rs.EOF
                .Cells(iRow, 3) = rs.Fields("Decription").Value
                .Cells(iRow, 4) = rs.Fields("TGSPartNo").Value
                .Cells(iRow, 5) = rs.Fields("Material/Part").Value
                .Cells(iRow, 7) = rs.Fields("Size").Value
                .Cells(iRow, 8) = rs.Fields("Qty").Value
                
                iRow = iRow + 1
                rs.MoveNext
            Loop
        End If
        rs.Close: Set rs = Nothing

End If

If cbo.Value = "Dropside" Then
    
End If
 
If cbo.Value = "Bevalite" Then
    
End If

End Sub
Function FindTippa(Source As String, Position As Integer)

Dim ws As Worksheet
Dim arr() As String

Set ws = ThisWorkbook.Worksheets("Job Card Master")

arr = VBA.Split(ws.Range("E4"), " ")
xCount = UBound(arr)
If xCount < 1 Or (Position - 1) > xCount Or Position < 0 Then
    Tippa = ""
Else
    Tippa = arr(Position - 1)
End If
End Function
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
With your thread title saying find first word in a cell, why would you use a function when one line will suffice
VBA Code:
BodyType = Split(Range("E4").Value, " ")(0)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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