Find, Copy Equivalent, Paste in Different Sheet

Stonesteel

Board Regular
Joined
Apr 27, 2010
Messages
81
Greetings!

Microsoft Excel 2007

Can you guys assist me, I am using Excel2007. I want to make a vba formula that will find a certain value in another sheet then will paste its equivalent value to another sheet. let's have an example.

i have this ESN "0A003ED50503" currently in cell "D384" in sheet "Status" and i want to find it in column "B" in another sheet "Licenses", and if found, i will copy its equivalent which i called "License" and will paste to another cell "M384" same row as ESN in the source sheet (Status).

esnfind1.jpg



esnfind2.jpg



esnfind3.jpg


Note: please do not suggest of using Vlookup, I already tried it and it responds for a long time since single change in a row where vlookup is located will make it scan for changes, i have 977 thousand licenses in Licenses Sheet. imagine how long it will scan. :biggrin:. so i am asking for a vba formula so that 1 click is when finding or lookup will only take place.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I'd use a sub:
Code:
Sub GetLicences()

Dim c As Range
Dim Rng As Range


Set Rng = Sheets("Licences").Range("B:B")

For Each c In Selection
    With c
        If Application.WorksheetFunction.CountIf(Rng, .Value) > 0 Then    'makes sure a match is found
            .Offset(0, 9).Value = Rng.Find(.Value, Rng.Cells(1, 1)).Offset(0, 1).Value
        End If
    End With
Next c

End Sub
But since you wanted a function:
Code:
Function Licence(ESN As String) As String

Dim Rng As Range

Set Rng = Sheets("Licences").Range("B:B")

        If Application.WorksheetFunction.CountIf(Rng, ESN) > 0 Then    'makes sure a match is found
            Licence = Rng.Find(ESN, Rng.Cells(1, 1)).Offset(0, 1).Value
        Else
            Licence = "No Match"
        End If

End Function
 
Upvote 0
i tried to put the sub in a command button like this..

Code:
Private Sub CommandButton1_Click()
Call ip_address
End Sub
Private Sub CommandButton2_Click()
Call license_upgrade
End Sub
Private Sub CommandButton3_Click()
Call GetLicences
End Sub

and created a module with the sub given. but when I tried to click the command button, nothing happens, don't know what seems to be the problem. can you help me revise the code Misca? I really appreciate your help. :)
 
Upvote 0
If your command buttons are placed on the sheet you can simply right click the button and attach the macro to it. Should work as it is as long as you have selected some ESNs for it to get the licences for.

From your code I get a feeling you have made a form and try to run the macros from the form, right? If that is the case the macro I wrote has a problem finding the selection to find the Licences for: When the form is active the code needs to be told the sheet references.
 
Upvote 0
nope, I am not using any form, i found the problem, it seems that in your code,
Code:
Dim Rng As Range


Set Rng = Sheets("Licences").Range("[COLOR=red]B:B[/COLOR]") 'replaced it with "[COLOR=red]A:A[/COLOR]"

For Each c In Selection
since we are offsetting, you are pinpointing to a column "B:B" where licenses are also located. I replaced it with range "A:A" where ESNs are located and it worked. Thank You Very Much Misca for your help, i really appreciate it... hope you could help me again soon, :biggrin::biggrin::biggrin:
 
Upvote 0
PS.

I'd like to put a message if no license was found, how should i put the code like this in your sub code?

Else
Licence = "No License"


thanks again.
 
Upvote 0
Try:
Code:
Sub GetLicences2()

Dim c As Range
Dim Rng As Range
Dim Licence As String


Set Rng = Sheets("Licences").Range("A:A")

For Each c In Selection
    
    With c
        
        'Gets the Licence:
        If Application.WorksheetFunction.CountIf(Rng, .Value) > 0 Then    'makes sure a match is found
            Licence = Rng.Find(.Value, Rng.Cells(1, 1)).Offset(0, 1).Value
        Else
            Licence = "No Licence"
        End If
        
        .Offset(0, 9).Value = Licence   'Writes the Licence
        
    End With
Next c

End Sub
 
Upvote 0
Yey! it worked! You are such a very big help! now my work process may doubled or tripled. Thank you very much again for your help, i really really appreciate it Misca! :-D :) :grin:
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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