Issue with VBA Find function

Cdn_Medic

New Member
Joined
Jan 30, 2014
Messages
6
Good day Excel peeps,

I have run into an issue trying to code a document for work.

I want to look for a string store in the variable "name". If that string is found, I want to add 1 to which ever number is in column I. If the string is not found, I want the values of column A, F and I to be respectively the variable name, nsn and qty1.

Here is the code I have:

Code:
Private Sub CommandButton5_Click()
Dim name As String
Dim nsn As String
Dim qty1 As Integer
Dim qty2 As Integer
Dim rgFound As Range


name = Sheets("RightLocker").Range("A1").value
nsn = Sheets("RightLocker").Range("C2").value
qty1 = 1


With Sheets("OrderForm").Range("A11:A45")
Set rgFound = .Find(What:=name)


If Not rgFound Is Nothing Then
Set outsh = Sheets("Orderform")
    outsh.Range("A15").value = "Test"
Else
Set outsh = Sheets("Orderform")
outrow = outsh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    outsh.Cells(outrow, 1).value = name
    outsh.Cells(outrow, 6).value = nsn
    outsh.Cells(outrow, 9).value = qty1
End If
End With


End Sub

This part works perfectly:

Code:
Else
Set outsh = Sheets("Orderform")
outrow = outsh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    outsh.Cells(outrow, 1).value = name
    outsh.Cells(outrow, 6).value = nsn
    outsh.Cells(outrow, 9).value = qty1

But I can't get this part to work:

Code:
If Not rgFound Is Nothing Then
Set outsh = Sheets("Orderform")
    outsh.Range("A15").value = "Test"
[/code ]

Any advice?

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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