Search for entered value in another tab

skittlz

New Member
Joined
Oct 26, 2012
Messages
33
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with multiple tabs. In the tab titled "Cal/PM", The user will make an entry in Column A, and is supposed trigger the code below:

VBA Code:
Dim Asset As String
Dim spec As String
Dim cal As String
Dim pm As String


Private Sub Worksheet_Change(ByVal Target As Range)
' Check if the changed cell is column A
    If Not Intersect(Target, Target.Worksheet.Range("A:A")) Is Nothing Then
        Asset = Target.Value
   
    Sheets("Equipment - Initial Entry").Columns("A:A").Find(What:=Asset, After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate

spec = Trim(ActiveCell.Offset(0, 4)) 'copy spec#
cal = Trim(ActiveCell.Offset(0, 5)) 'copy Cal yes/no
pm = Trim(ActiveCell.Offset(0, 6)) 'copy PM Yes/no
MsgBox spec
    End If
 
End Sub

Basically, the code is "take value entered in "Column A" of "Cal/PM" tab, go to "Equipment - Initial Entry" tab, and get the spec, cal, and PM details.

Unfortunately my "Find" function isn't working - from what I can tell - the code doesn't like to go to a different tab to store the values. How do I get around this issue?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
this?
VBA Code:
Dim Asset As String
Dim spec As String
Dim cal As String
Dim pm As String


Private Sub Worksheet_Change(ByVal Target As Range)
' Check if the changed cell is column A
    If Not Intersect(Target, Target.Worksheet.Range("A:A")) Is Nothing Then
        Asset = Target.Value
Sheets("Equipment - Initial Entry").Select

    Sheets("Equipment - Initial Entry").Columns("A:A").Find(What:=Asset, After:=Range("a1"), LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate

spec = Trim(ActiveCell.Offset(0, 4)) 'copy spec#
cal = Trim(ActiveCell.Offset(0, 5)) 'copy Cal yes/no
pm = Trim(ActiveCell.Offset(0, 6)) 'copy PM Yes/no
MsgBox spec
    End If

End Sub
 
Upvote 0
or better yet
VBA Code:
Dim Asset As String
Dim spec As String
Dim cal As String
Dim pm As String
Dim aCell As Range
Private Sub Worksheet_Change(ByVal Target As Range)
' Check if the changed cell is column A
    If Not Intersect(Target, Target.Worksheet.Range("A:A")) Is Nothing Then
        Asset = Target.Value


     Set aCell = Sheets("Equipment - Initial Entry").Columns("A:A").Find(What:=Asset, After:=Range("a1"), LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

spec = Trim(aCell.Offset(0, 4)) 'copy spec#
cal = Trim(aCell.Offset(0, 5)) 'copy Cal yes/no - not sure what  you are doing with this unless you  use this MsgBox spec & vbCr & cal & vbCr & pm
pm = Trim(aCell.Offset(0, 6)) 'copy PM Yes/no - not sure what  you are doing with this unless you use this MsgBox spec & vbCr & cal & vbCr & pm
MsgBox spec
'or MsgBox spec & vbCr & cal & vbCr & pm
    End If

End Sub
 
Upvote 0
Solution
THAT'S IT!! oof what a pain. I had it as your original entry (where sheet was selected as a sperate line item) - but that wasn't working. The only thing that changed from what I can tell is the Set aCell =

What was the problem? Why was it not working? I may have to do it a few more times.
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,507
Members
452,194
Latest member
Lowie27

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top