Macro

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
I need the following:

column B will have any number 1-1000 .
If B5 for example = 3 i want D5 to = "Sheet Info" Find that # (3) in column A select the cell right beside it in column B and paste it.
remember: it can be any number 1-1000 in any row(column B)

What macro would work for this?
I do now want to use a formula because a number may be manually entered, deleting the formula.

Any ideas?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
That's a Vlookup..

Try

=VLOOKUP(B5,'Sheet Info'!$A:$B,2,FALSE)


instead of "Sheet Info" can it be Sheet4?

No, formulas can't use the codename for a sheet, only the tab name.
However, if the reason you ask is because the sheet might get renamed sometime in the future,
Don't worry, any formula(s) referring to a sheet that is renamed will automatically adjust themselves to the new sheet name.


Hope that helps.
 
Upvote 0
I need this to be code in VBA. Numbers could be manually entered in that cell deleting the formula. Do you know the code that would be used?
 
Upvote 0
Try this in the sheet's module (not a standard module)

Right click the sheet's tab, View Code
Paste it there

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range, c As Range, Fnd As Range
Application.EnableEvents = False
 
Set MyRange = Intersect(Target, Range("B:B"))
If Not MyRange Is Nothing Then
    For Each c In MyRange
        On Error Resume Next
        Set Fnd = Sheet4.Range("A:A").Find(c)
        On Error GoTo 0
        If Not Fnd Is Nothing Then
            c.Offset(0, 2).Value = Fnd.Offset(0, 1).Value
        End If
        Set Fnd = Nothing
    Next c
End If
 
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

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