LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Find Number Then Do Until Loop Question

Works great man! Thanks for the quick response! I'm glad I was at least
close to the correct code!

"ilia" wrote:

This is what I came up with, which seems to work - not clear whether
this is the behavior you want, but it will populate the first blank
4th column (counting from 2 ala 2 6 10 14 etc) and populate with
RefNumber and combobox values:

Sub FindReferenceNumber()
Dim myRef As Excel.Range
Dim i As Long


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
Set myRef = Cells(1, 4 * i + 2)
Exit Do
End If
Next i
Loop
End If


With myRef
.Value = lblRefNumber.Caption
.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


On Nov 29, 1:57 pm, RyanH wrote:
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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Find previous number and find next number in column DoubleZ Excel Discussion (Misc queries) 4 March 4th 09 08:51 PM
Find Loop and then Loop again Don Guillett Excel Programming 0 December 7th 06 06:05 PM
Loops to find blanks then loop to find populated Bevy Excel Programming 0 June 1st 06 04:50 PM
Loop and find less than... John Excel Programming 2 August 30th 05 03:34 PM


All times are GMT +1. The time now is 04:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"