Problems with extracting data from worksheet

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi and thanks in advance for your help,

I have the following code which is meant to get two different pieces of data from two different worksheets in the same workbook:

Code:
Private Sub CBanswer_Click()

Dim s As Worksheet, myValue As String, f As Range
Dim Q As Worksheet
Dim myvalue2 As String
Dim p As Range


    Set s = Worksheets("Lists")
    myValue = Comboxmajor.Value
    Set f = s.Range("K1:K500").Find(myValue, LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        TBhistory.Value = f.Offset(0, 1).Value
    Else
        MsgBox "Does not exists : " & myValue
    End If




Set Q = Worksheets("Interpretations")
    myvalue2 = Comboxmajor.Value & " " & Comboxarea.Value
    Set p = Q.Range("A:A").Find(myvalue2, LookIn:=xlValues, lookat:=xlWhole)
    If Not p Is Nothing Then
        TBanswer.Value = p.Offset(0, 1).Value
    Else
        MsgBox "Does not exists : " & myvalue2
    End If


End Sub

It seems to work fine for TBhistory but it only gets data from column A on the "Interpretations" worksheet.

I've tripple checked the value in the Interpretations worksheet to make sure they are right.

Many thanks in advance for any help,

Mike
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi and thanks in advance for your help,

I have the following code which is meant to get two different pieces of data from two different worksheets in the same workbook:

Code:
Private Sub CBanswer_Click()

Dim s As Worksheet, myValue As String, f As Range
Dim Q As Worksheet
Dim myvalue2 As String
Dim p As Range


    Set s = Worksheets("Lists")
    myValue = Comboxmajor.Value
    Set f = s.Range("K1:K500").Find(myValue, LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        TBhistory.Value = f.Offset(0, 1).Value
    Else
        MsgBox "Does not exists : " & myValue
    End If




Set Q = Worksheets("Interpretations")
    myvalue2 = Comboxmajor.Value & " " & Comboxarea.Value
    Set p = [COLOR=#ff0000][B]Q.Range("A:A")[/B][/COLOR].Find(myvalue2, LookIn:=xlValues, lookat:=xlWhole)
    If Not p Is Nothing Then
        TBanswer.Value = p.Offset(0, 1).Value
    Else
        MsgBox "Does not exists : " & myvalue2
    End If


End Sub

It seems to work fine for TBhistory but it only gets data from column A on the "Interpretations" worksheet.

I've tripple checked the value in the Interpretations worksheet to make sure they are right.

Many thanks in advance for any help,

Mike
The bit in bold red font is limiting the search to col A. Change it to whatever range you want to search for myvalue2.
 
Upvote 0
Joe thanks very much, I though A:A wouldve been for the whole worksheet.
Thanks for pointing out the mistake, it works great now :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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