Macro to Find and mark cell "Y"

Reganovski

New Member
Joined
Nov 11, 2012
Messages
9
I recorded the below macro trying to figure out what needs to be done for my excel sheet

My sheet has 7,000 rows on it and I want a macro to do the follow:

1) Find a number I put in i.e. 510038 has to be an exact match
2) On the cell next to it, I want it to automatically mark it "Y"
3) I will be doing this 7000 times as its a kinda of attendance sheet.


The below does what I want but naturally I need to put in different numbers and selecting/putting the Y in the correct cell.

Thanks in advance

Sub Macro1()
Cells.Find(What:="510038", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range("F27").Select
ActiveCell.FormulaR1C1 = "Y"
Range("F28").Select
ActiveWorkbook.Save
End Sub
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Something like this?

Code:
Option Explicit

Sub Attendance()
Dim ws As Worksheet
Dim rng As Range
Dim resp As Variant

Set ws = ActiveSheet 'change if you intend calling this from another sheet
Set rng = ws.Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row) 'you might need to change the first part of this range too

resp = InputBox("Please enter lookup value...", "Input")

On Error GoTo errHandler

rng.Find(resp).Offset(, 1) = "Y"

Exit Sub

errHandler:
    MsgBox "Data not found in worksheet"
    Err.Clear
    
End Sub
 
Upvote 0
Thanks nuked.

I'm not sure this is finding an exact match?
I might have number 10001 and 110001 so when I do a search for 10001, it doesnt mark the 110001, just 10001.
Could I maybe add a message to confirm that its the right account number?
 
Upvote 0
Try this:-

Code:
Option Explicit

Sub Attendance()
Dim ws As Worksheet
Dim rng As Range
Dim resp As Variant

Set ws = ActiveSheet 
Set rng = ws.Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)resp = InputBox("Please enter lookup value...", "Input")

On Error GoTo errHandler

rng.Find(resp, LookAt:=xlWhole).Offset(, 1) = "Y"

Exit Sub

errHandler:
    MsgBox "Data not found in worksheet"
    Err.Clear
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,655
Messages
6,056,571
Members
444,877
Latest member
kat517

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