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:
This part works perfectly:
But I can't get this part to work:
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