Excel - Find a variable in a selection

April 2017




Issue


I have data added each day and I was wanting to add a button that basically jumps to todays date and then copies data to the attached row. Copying is fine but so far however I can't even select the date.
Column A has the dates which can change, but will always contain today. C3=Today() . I have tried to set aVab, but I am a complete novice and can't find the answer to this simple query. I seem to always get error 91 object variable not set thingy.

Dim aVab As Date  
    aVab = Range("C3").Value  
          
    Columns("A:A").Select  
    Selection.Find(What:=aVab, After:=ActiveCell, LookIn:=xlValues, LookAt _  
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _  
    False, MatchFormat:=False).Activate  
    ActiveCell.Select

Solution


If the date [Today())] will appear in the column one time and you want to select that cell, this will do the trick.
Hope this helps!


Dim aVab   
Dim c As Range   
aVab = Range("C3").Value   


For Each c In Range("A1:A65536")   

If c = aVab Then   
c.Select   

End If   

Next c  

Note


Thanks to Wut Up WutUp for this tip on the forum.

Related


Published by aakai1056. Latest update on August 14, 2012 at 10:08 AM by deri58.
This document, titled "Excel - Find a variable in a selection," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).