If I create a variable and call it End_date how can I use it in the sort
function?
I want to replace the quot;02/26/06quot; value with this variable. I've tried just
replacing it with Cells.Find(What:=End_date,..... and it fails. I've also
tried placing it in brackets and that fails too.
Cells.Find(What:=quot;02/26/06quot;, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).ActivateHi El,
See last topic in Chip Pearson's
www.cpearson.com/excel/DateTimeVBA.htm
you have to effectively use a dateserial number the actual stored value of the date
as days past Dec 31, 1899 as recorded internally in Excel (actually it's the wrong value).
--
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: www.mvps.org/dmcritchie/excel/excel.htm
Search Page: www.mvps.org/dmcritchie/excel/search.htm
quot;El Beequot; gt; wrote in message news
gt; If I create a variable and call it End_date how can I use it in the sort
gt; function?
gt; I want to replace the quot;02/26/06quot; value with this variable. I've tried just
gt; replacing it with Cells.Find(What:=End_date,..... and it fails. I've also
gt; tried placing it in brackets and that fails too.
gt;
gt; Cells.Find(What:=quot;02/26/06quot;, After:=ActiveCell, LookIn:=xlValues, LookAt _
gt; :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
gt; MatchCase:= _
gt; False, SearchFormat:=False).Activate
gt;
Forget the date value in the variable, let's say I want to find quot;110.05quot; one
time and the next time I want to find quot;Michaelquot;; both values would be a
string. I want to use a variable name inside the find function. What is the
syntax for using this variable name instead of hard coded values as shown in
the example?
quot;David McRitchiequot; wrote:
gt; Hi El,
gt; See last topic in Chip Pearson's
gt; www.cpearson.com/excel/DateTimeVBA.htm
gt;
gt; you have to effectively use a dateserial number the actual stored value of the date
gt; as days past Dec 31, 1899 as recorded internally in Excel (actually it's the wrong value).
gt;
gt; --
gt; HTH,
gt; David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
gt; My Excel Pages: www.mvps.org/dmcritchie/excel/excel.htm
gt; Search Page: www.mvps.org/dmcritchie/excel/search.htm
gt;
gt; quot;El Beequot; gt; wrote in message news
gt; gt; If I create a variable and call it End_date how can I use it in the sort
gt; gt; function?
gt; gt; I want to replace the quot;02/26/06quot; value with this variable. I've tried just
gt; gt; replacing it with Cells.Find(What:=End_date,..... and it fails. I've also
gt; gt; tried placing it in brackets and that fails too.
gt; gt;
gt; gt; Cells.Find(What:=quot;02/26/06quot;, After:=ActiveCell, LookIn:=xlValues, LookAt _
gt; gt; :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
gt; gt; MatchCase:= _
gt; gt; False, SearchFormat:=False).Activate
gt; gt;
gt;
gt;
gt;
I think you did fine with the expression.
But vba, dates, find don't always play nice.
dim End_Date as date
end_date = dateserial(2006,2,26)
Cells.Find(What:=end_date, ...
or
Cells.Find(What:=clng(end_date)
Sometimes, if you know the format that should match up...
Cells.Find(What:=format(end_date,quot;mm/dd/yyquot;), ...
El Bee wrote:
gt;
gt; Forget the date value in the variable, let's say I want to find quot;110.05quot; one
gt; time and the next time I want to find quot;Michaelquot;; both values would be a
gt; string. I want to use a variable name inside the find function. What is the
gt; syntax for using this variable name instead of hard coded values as shown in
gt; the example?
gt;
gt; quot;David McRitchiequot; wrote:
gt;
gt; gt; Hi El,
gt; gt; See last topic in Chip Pearson's
gt; gt; www.cpearson.com/excel/DateTimeVBA.htm
gt; gt;
gt; gt; you have to effectively use a dateserial number the actual stored value of the date
gt; gt; as days past Dec 31, 1899 as recorded internally in Excel (actually it's the wrong value).
gt; gt;
gt; gt; --
gt; gt; HTH,
gt; gt; David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
gt; gt; My Excel Pages: www.mvps.org/dmcritchie/excel/excel.htm
gt; gt; Search Page: www.mvps.org/dmcritchie/excel/search.htm
gt; gt;
gt; gt; quot;El Beequot; gt; wrote in message news
gt; gt; gt; If I create a variable and call it End_date how can I use it in the sort
gt; gt; gt; function?
gt; gt; gt; I want to replace the quot;02/26/06quot; value with this variable. I've tried just
gt; gt; gt; replacing it with Cells.Find(What:=End_date,..... and it fails. I've also
gt; gt; gt; tried placing it in brackets and that fails too.
gt; gt; gt;
gt; gt; gt; Cells.Find(What:=quot;02/26/06quot;, After:=ActiveCell, LookIn:=xlValues, LookAt _
gt; gt; gt; :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
gt; gt; gt; MatchCase:= _
gt; gt; gt; False, SearchFormat:=False).Activate
gt; gt; gt;
gt; gt;
gt; gt;
gt; gt;
--
Dave Peterson
- Jun 04 Wed 2008 20:44
Sort : how can I use a variable in a VB sort function?
close
全站熱搜
留言列表
發表留言