R
RyanH
I have a reference number as a Label in a Userform. I want to search all
columns for the reference number in Row 1 on Sheets1. If the reference
number is found, data that was entered in the Userform will save over top of
the old data that was in that reference numbers column. If the reference
number is not found I want the code to find the next empty cell (counting
every 4 columns) and apply the new data below the new empty cell. Here is
what I have so far?
Sub FindReferenceNumber ()
Dim myRef As Range, blank As Range
Set myRef = Worksheets("Plastic Faces").Rows(1).Find
(What:=lblRefNumber.Caption, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If myRef Is Nothing Then 'if reference number is not found
Do
For i = 0 To 63 'searches all columns in row 1
If IsEmpty(Cells(1, 4 * i + 2)) = True Then
Cells(1, 4 * i + 2) = myRef
Else
Exit Do
End If
Next i
Loop
End If
With Sheets("Plastic Faces").Range(myRef.Address)
.Offset(1, 0).Value = cboMaterial 'name of combobox
.Offset(2, 0).Value = cboMoldStyle 'name of combobox
.Offset(3, 0).Value = cboRadius 'name of combobox
.Offset(4, 0).Value = cboMoldSeam 'name of combobox
End With
End Sub
columns for the reference number in Row 1 on Sheets1. If the reference
number is found, data that was entered in the Userform will save over top of
the old data that was in that reference numbers column. If the reference
number is not found I want the code to find the next empty cell (counting
every 4 columns) and apply the new data below the new empty cell. Here is
what I have so far?
Sub FindReferenceNumber ()
Dim myRef As Range, blank As Range
Set myRef = Worksheets("Plastic Faces").Rows(1).Find
(What:=lblRefNumber.Caption, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If myRef Is Nothing Then 'if reference number is not found
Do
For i = 0 To 63 'searches all columns in row 1
If IsEmpty(Cells(1, 4 * i + 2)) = True Then
Cells(1, 4 * i + 2) = myRef
Else
Exit Do
End If
Next i
Loop
End If
With Sheets("Plastic Faces").Range(myRef.Address)
.Offset(1, 0).Value = cboMaterial 'name of combobox
.Offset(2, 0).Value = cboMoldStyle 'name of combobox
.Offset(3, 0).Value = cboRadius 'name of combobox
.Offset(4, 0).Value = cboMoldSeam 'name of combobox
End With
End Sub