Get Cell Value From Name Range Excel 2007 VBA

bkatsma

New Member
Joined
Jan 9, 2013
Messages
20
Hi,

I am looking for some help creating a VBA that will help me. I have two worksheets, contractor & list. Assume that Column (A) on the "contractor" worksheet is a named range from Column (A) on the "list" worksheet. On the "contractor" worksheet I would like to put in the contractors name, and auto populate the pay value in column (B). I have been using a Vlookup formula, but need to automate this process a bit more. Any help would be great. I hope this make sense.

"Contractor" worksheet - Two columns: (A) I will input the contractors name from a dropdown list based on name range from my "list" worksheet. (B) is where I would like to populate the pay base on column (B) in my "list" worksheet.

Contractor (A)Pay (B)
Jill
Fred
Jack
Megan

<tbody>
</tbody>

"List" worksheet - Two columns; (A) is the list of contractors & (B) is the pay.
ContractorPay
Sarah$18.00
Jill$20.00
Tim$22.00
Fred$20.00
Jack$15.00
Megan$15.00

<tbody>
</tbody>


As an aside, does anyone know how to add an attachment. I know examples help, and would have like to include one if I could find out how.
 

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.
You can to try this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim CFind As Range
    Set CFind = Sheets("List").[A2:A65536].Find(Target, LookIn:=xlFormulas, lookat:=xlWhole)
    If Not CFind Is Nothing Then
        Target.Offset(, 1) = CFind.Offset(, 1)
    End If
End Sub
 
Upvote 0
You can to try this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim CFind As Range
    Set CFind = Sheets("List").[A2:A65536].Find(Target, LookIn:=xlFormulas, lookat:=xlWhole)
    If Not CFind Is Nothing Then
        Target.Offset(, 1) = CFind.Offset(, 1)
    End If
End Sub

I entered the code within the contractors worksheet, not a module. I am getting an error. "Run time error #9, Subscript out of range". Any thoughts?
 
Upvote 0
I entered the code within the contractors worksheet, not a module. I am getting an error. "Run time error #9, Subscript out of range". Any thoughts?
The error may be you change the cell is not Column A.
I edited code form #2, please see code below
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim CFind As Range
    If Target.Column = 1 Then
        Set CFind = Sheets("List").[A2:A65536].Find(Target, LookIn:=xlFormulas, lookat:=xlWhole)
        If Not CFind Is Nothing Then
            Target.Offset(, 1) = CFind.Offset(, 1)
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

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