ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using variables to make a date and using find method to find that. (https://www.excelbanter.com/excel-programming/327925-using-variables-make-date-using-find-method-find.html)

KyWilde

Using variables to make a date and using find method to find that.
 
I have the month in a variable "mon1", the day in a variable "day1" , and the
year in a variable "year1". I need to use the find method to find this
specific date and here is the code I am using...
Set wks = ActiveSheet
Set rngSearch = wks.Cells
Set rngFound = rngSearch.Find("mon1 / day1 / year1")
Debug.Print rngFound.Address

This doesn't work. But if I use "4/1/2005" in place of the variables it
works just fine. What do I need to do to make this work? Thanks!!

Toppers

Using variables to make a date and using find method to find that.
 

Your string in quotes was treated as literally a string "mon1/day1/year1"
and not as variables concatenated with "/".

Use:

Set rngFound = rngSearch.Find(mon1 & "/ " & day1 & "/ " & year1)

HTH

"KyWilde" wrote:

I have the month in a variable "mon1", the day in a variable "day1" , and the
year in a variable "year1". I need to use the find method to find this
specific date and here is the code I am using...
Set wks = ActiveSheet
Set rngSearch = wks.Cells
Set rngFound = rngSearch.Find("mon1 / day1 / year1")
Debug.Print rngFound.Address

This doesn't work. But if I use "4/1/2005" in place of the variables it
works just fine. What do I need to do to make this work? Thanks!!


KyWilde

Using variables to make a date and using find method to find t
 
Thank you Toppers...!!!

"Toppers" wrote:


Your string in quotes was treated as literally a string "mon1/day1/year1"
and not as variables concatenated with "/".

Use:

Set rngFound = rngSearch.Find(mon1 & "/ " & day1 & "/ " & year1)

HTH

"KyWilde" wrote:

I have the month in a variable "mon1", the day in a variable "day1" , and the
year in a variable "year1". I need to use the find method to find this
specific date and here is the code I am using...
Set wks = ActiveSheet
Set rngSearch = wks.Cells
Set rngFound = rngSearch.Find("mon1 / day1 / year1")
Debug.Print rngFound.Address

This doesn't work. But if I use "4/1/2005" in place of the variables it
works just fine. What do I need to do to make this work? Thanks!!



All times are GMT +1. The time now is 12:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com