Hi All
Originally the code below in Column "I" was for just 500 rows it has now been extended to 5,000 - for 500 rows it ran and did the necessary in about 10 Seconds after expanding the rows - ran it yesterday and it took approx 11 minutes - did the job perfectly no problems - is it just the expansion of rows causing the time taken? if so we accept it as OK. Or can you guys find away round this small time problem?
Regards
Sooty8
[VBA]
Private shIndex As Long
Private Sub CommandButton1_Click()
Dim i
Application.ScreenUpdating = False
For i = 2 To Cells(Rows.Count, "I").End(xlUp).Row
tb1a = Cells(i, "I")
Find_Click
enterdata_Click
Next
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click()
Call Module11.ClearText
End Sub
Private Sub enterdata_Click()
Application.ScreenUpdating = False
shIndex = 1
SearchForValue
Application.ScreenUpdating = True
End Sub
Private Sub SearchForValue()
Application.ScreenUpdating = False
Dim rngFound As Range
Dim rngToSearch As Range
Dim FindWhat As String
Dim Matches As Boolean
Dim j As Long
Set rngFound = Nothing
FindWhat = tb1a.Text
For j = 2 To Sheets.Count
Set rngToSearch = Worksheets(j).Columns("A")
Set rngFound = rngToSearch.Find(What:=Trim(FindWhat), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=False)
tb1a.SetFocus
If Not (rngFound Is Nothing) Then
With Me
.Tb2.Text = rngFound.Offset(0, 2).Value
.Tb3.Text = rngFound.Offset(0, 1).Value
.Tb4.Text = rngFound.Offset(0, 4).Value
For i = 5 To 24
Set Ctrl = Controls("Tb" & i)
If Len(Trim(Ctrl.Text)) <> 0 Then _
rngFound.Offset(0, i) = Ctrl.Text
Next
End With
Else
shIndex = shIndex + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Private Sub Tb1A_Change()
tb1a.Value = UCase(tb1a.Value)
End Sub
Private Sub Find_Click()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim vecRows As Variant
Dim iRow As Long
Dim i As Long
Set ws = Worksheets("CSV")
With Me
vecRows = Application.Evaluate("IF(TRIM(I2:I5000)=""" & Trim(tb1a) & """,ROW(I2:I5000))")
If .tb1a.Text <> "" Then
For i = LBound(vecRows) To UBound(vecRows)
If vecRows(i, 1) Then
iRow = vecRows(i, 1)
Select Case ws.Cells(iRow, "H").Value2
Case 4161: .Tb5.Text = ws.Cells(iRow, 10): .Tb6.Text = ws.Cells(iRow, 11)
Case 5092: .Tb7.Text = ws.Cells(iRow, 10): .Tb8.Text = ws.Cells(iRow, 11)
Case 5064: .Tb9.Text = ws.Cells(iRow, 10): .Tb10.Text = ws.Cells(iRow, 11)
Case 4180: .Tb11.Text = ws.Cells(iRow, 10): .Tb12.Text = ws.Cells(iRow, 11)
Case 4048: .Tb13.Text = ws.Cells(iRow, 10): .TB14.Text = ws.Cells(iRow, 11)
Case 4064: .Tb15.Text = ws.Cells(iRow, 10): .Tb16.Text = ws.Cells(iRow, 11)
Case 5029: .Tb17.Text = ws.Cells(iRow, 10): .Tb18.Text = ws.Cells(iRow, 11)
Case 4087: .Tb19.Text = ws.Cells(iRow, 10): .Tb20.Text = ws.Cells(iRow, 11)
Case 5042: .Tb21.Text = ws.Cells(iRow, 10): .Tb22.Text = ws.Cells(iRow, 11)
Case 4199: .Tb23.Text = ws.Cells(iRow, 10): .Tb24.Text = ws.Cells(iRow, 11)
End Select
End If
Next i
End If
End With
Application.ScreenUpdating = True
End Sub
[/VBA]