Hello All,<o
></o
>
I have Sheet1 , Sheet2 and Sheet3 in a workbook. <o
></o
>
Can anyone edit the code vba code below to make it work justonly SHEET1 and not other sheets. <o
></o
>
Thank you.
PubliccurSheet<o
></o
>
PrivateSub btnsearch1_Click()<o
></o
>
Dimi, LastRow, caseFound As Boolean<o
></o
>
Application.ScreenUpdating= False<o
></o
>
cassFound= False<o
></o
>
IfMe.txtSrch = "" Then<o
></o
>
ExitSub<o
></o
>
EndIf<o
></o
>
curSheet= ActiveSheet.Name<o
></o
>
'hideLocation 2 and 3 fields if next case does not have multiple locations<o
></o
>
Me.txtLoc2.Visible= False<o
></o
>
Me.txtLoc2.Value= ""<o
></o
>
Me.lblLoc2.Visible= False<o
></o
>
Me.txtLoc3.Visible= False<o
></o
>
Me.txtLoc3.Value= ""<o
></o
>
Me.lblLoc3.Visible= False<o
></o
>
ForEach ws In Sheets<o
></o
>
ws.Activate<o
></o
>
<o
></o
>
'set LastRow for current worksheet beingsearched<o
></o
>
LastRow= ws.Range("A" & Rows.count).End(xlUp).Row 'set last row number for current worksheet<o
></o
>
'loop through column C of worksheet beingsearched and evaluated case number match<o
></o
>
Fori = 2 To LastRow<o
></o
>
IfUCase(Cells(i, "A").Value) = UCase(Me.txtSrch) Then 'convert to upper case for matching. VBA is case sensitive<o
></o
>
caseFound= True<o
></o
>
'Me.txtDname= ws.Range("D" & i).Value<o
></o
>
IfMe.txtLoc.Value = "" Then<o
></o
>
Me.txtLoc= ws.Range("B" & i).Value<o
></o
>
EndIf<o
></o
>
'if a second location exists for casenumber, show Loc2 label and text box and enter the location<o
></o
>
IfMe.txtLoc2.Value = "" And ws.Range("B" & i).Value<> Me.txtLoc Then<o
></o
>
Me.txtLoc2.Visible= True<o
></o
>
Me.lblLoc2.Visible= True<o
></o
>
Me.txtLoc2.Value= ws.Range("B" & i).Value<o
></o
>
EndIf<o
></o
>
'if a third location exists for case number,show Loc3 label and text box and enter the location<o
></o
>
IfMe.txtLoc3.Value = "" And Me.txtLoc2.Value <> "" Andws.Range("B" & i).Value <> Me.txtLoc2 Andws.Range("B" & i).Value <> Me.txtLoc Then<o
></o
>
Me.txtLoc3.Visible= True<o
></o
>
Me.lblLoc3.Visible= True<o
></o
>
Me.txtLoc3.Value= ws.Range("B" & i).Value<o
></o
>
EndIf<o
></o
>
EndIf<o
></o
>
Nexti<o
></o
>
Nextws<o
></o
>
Sheets(curSheet).Activate<o
></o
>
'Me.txtDname.SetFocus<o
></o
>
IfcaseFound = False Then<o
></o
>
MsgBox"No record found for Case " & Me.txtSrch.Value, vbInformation,"Not Found"<o
></o
>
EndIf<o
></o
>
EndSub<o
></o
>
<o
> </o
>
PrivateSub txtSrch_Enter()<o
></o
>
Me.txtSrch.Value= ""<o
></o
>
Me.txtSrch.BackColor= &HFFFF& 'added for colortabuserform<o
></o
>
'Me.txtDname.Value= ""<o
></o
>
Me.txtLoc.Value= ""<o
></o
>
Me.txtLoc2.Value= ""<o
></o
>
Me.txtLoc3.Value= ""<o
></o
>
EndSub<o
></o
>
<o
> </o
>
PrivateSub UserForm_Activate()<o
></o
>
Me.lblLoc2.Visible= False<o
></o
>
Me.txtLoc2.Visible= False<o
></o
>
Me.lblLoc3.Visible= False<o
></o
>
Me.txtLoc3.Visible


I have Sheet1 , Sheet2 and Sheet3 in a workbook. <o


Can anyone edit the code vba code below to make it work justonly SHEET1 and not other sheets. <o


Thank you.
PubliccurSheet<o


PrivateSub btnsearch1_Click()<o


Dimi, LastRow, caseFound As Boolean<o


Application.ScreenUpdating= False<o


cassFound= False<o


IfMe.txtSrch = "" Then<o


ExitSub<o


EndIf<o


curSheet= ActiveSheet.Name<o


'hideLocation 2 and 3 fields if next case does not have multiple locations<o


Me.txtLoc2.Visible= False<o


Me.txtLoc2.Value= ""<o


Me.lblLoc2.Visible= False<o


Me.txtLoc3.Visible= False<o


Me.txtLoc3.Value= ""<o


Me.lblLoc3.Visible= False<o


ForEach ws In Sheets<o


ws.Activate<o


<o


'set LastRow for current worksheet beingsearched<o


LastRow= ws.Range("A" & Rows.count).End(xlUp).Row 'set last row number for current worksheet<o


'loop through column C of worksheet beingsearched and evaluated case number match<o


Fori = 2 To LastRow<o


IfUCase(Cells(i, "A").Value) = UCase(Me.txtSrch) Then 'convert to upper case for matching. VBA is case sensitive<o


caseFound= True<o


'Me.txtDname= ws.Range("D" & i).Value<o


IfMe.txtLoc.Value = "" Then<o


Me.txtLoc= ws.Range("B" & i).Value<o


EndIf<o


'if a second location exists for casenumber, show Loc2 label and text box and enter the location<o


IfMe.txtLoc2.Value = "" And ws.Range("B" & i).Value<> Me.txtLoc Then<o


Me.txtLoc2.Visible= True<o


Me.lblLoc2.Visible= True<o


Me.txtLoc2.Value= ws.Range("B" & i).Value<o


EndIf<o


'if a third location exists for case number,show Loc3 label and text box and enter the location<o


IfMe.txtLoc3.Value = "" And Me.txtLoc2.Value <> "" Andws.Range("B" & i).Value <> Me.txtLoc2 Andws.Range("B" & i).Value <> Me.txtLoc Then<o


Me.txtLoc3.Visible= True<o


Me.lblLoc3.Visible= True<o


Me.txtLoc3.Value= ws.Range("B" & i).Value<o


EndIf<o


EndIf<o


Nexti<o


Nextws<o


Sheets(curSheet).Activate<o


'Me.txtDname.SetFocus<o


IfcaseFound = False Then<o


MsgBox"No record found for Case " & Me.txtSrch.Value, vbInformation,"Not Found"<o


EndIf<o


EndSub<o


<o


PrivateSub txtSrch_Enter()<o


Me.txtSrch.Value= ""<o


Me.txtSrch.BackColor= &HFFFF& 'added for colortabuserform<o


'Me.txtDname.Value= ""<o


Me.txtLoc.Value= ""<o


Me.txtLoc2.Value= ""<o


Me.txtLoc3.Value= ""<o


EndSub<o


<o


PrivateSub UserForm_Activate()<o


Me.lblLoc2.Visible= False<o


Me.txtLoc2.Visible= False<o


Me.lblLoc3.Visible= False<o


Me.txtLoc3.Visible