I need to a search number in a list in cycle

michellin

Board Regular
Joined
Oct 4, 2011
Messages
56
Office Version
  1. 2019
Platform
  1. Windows
Hi there,

I receive a list to empty some locker, but i need to compare it to the active student list to empty only the one of the student not active.

I got a Sheet with the active student list(STUDENT), another sheet with the locker list(LOCKER).

I have merge the info i need, on a third sheet where the magic need to happen (CLEANUP).

On the sheet (CLEANUP), i got all my number for the locker in the collumn A, i'Ve got all the number for each student in colomn B, and there student name in column C.

My need: i need to match the number for each student and search it into the sheet. IF the macro find his number write in column D ''active''.

So the macro need to find in the sheet(STUDENT) the number of the student in the column A. Then search for it in the sheet(CLEANUP), in column B. IF the macro find the number, Write ''active'' in columnd D, on the same line.

And do it for each line in the (STUDENT) sheet. The number of line can change everytime. Here why i need to cycle it.

I've done that by hand a lot, and i knew for sure with macro, that can do it automatic.

Thanks you so much to helping me.

(In the picture, they are fake information to make sure nobody copy info of student)

If you need more info, or the excel workbook, i can give it to you.

Michellin
 

Attachments

  • CLEANUP ex.JPG
    CLEANUP ex.JPG
    134 KB · Views: 10
  • Student ex.JPG
    Student ex.JPG
    175 KB · Views: 12

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You could join the two tables in Power Query on the Common field. If you repost your data using XL2BB, I can demonstrate. As it stands, I cannot manipulate the data you have provided in pictures and am unwilling to recreate your files as that is time consuming and you have the data already.
 
Upvote 0
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim i As Long, srcWS As Worksheet, desWS As Worksheet, v1 As Variant, v2 As Variant, dic As Object
    Set srcWS = Sheets("STUDENT")
    Set desWS = Sheets("CLEANUP")
    v1 = srcWS.Range("A2", srcWS.Range("A" & Rows.Count).End(xlUp)).Resize(, 2).Value
    v2 = desWS.Range("B2", desWS.Range("B" & Rows.Count).End(xlUp)).Resize(, 2).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v1) To UBound(v1)
        If Not dic.exists(v1(i, 1)) Then
            dic.Add v1(i, 1), Nothing
        End If
    Next i
    For i = LBound(v2) To UBound(v2)
        If dic.exists(v2(i, 1)) Then
            desWS.Range("D" & i + 1) = "ACTIVE"
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
You could join the two tables in Power Query on the Common field. If you repost your data using XL2BB, I can demonstrate. As it stands, I cannot manipulate the data you have provided in pictures and am unwilling to recreate your files as that is time consuming and you have the data already.
Hi,
i will take a look into power Query, but i can't install the program xl2bb, i don't have acces into my comptuter... But thanks for the hint of power query.

Michellin
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Hi Fluff,

Thanks to pointing the user profiles to me, i just make the change into it.

Thanks
 
Upvote 0
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim i As Long, srcWS As Worksheet, desWS As Worksheet, v1 As Variant, v2 As Variant, dic As Object
    Set srcWS = Sheets("STUDENT")
    Set desWS = Sheets("CLEANUP")
    v1 = srcWS.Range("A2", srcWS.Range("A" & Rows.Count).End(xlUp)).Resize(, 2).Value
    v2 = desWS.Range("B2", desWS.Range("B" & Rows.Count).End(xlUp)).Resize(, 2).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v1) To UBound(v1)
        If Not dic.exists(v1(i, 1)) Then
            dic.Add v1(i, 1), Nothing
        End If
    Next i
    For i = LBound(v2) To UBound(v2)
        If dic.exists(v2(i, 1)) Then
            desWS.Range("D" & i + 1) = "ACTIVE"
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
Hi Mumps :)

Oh my god, that work great. Thanks for your help. Your the king :)

Michellin
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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