Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Two digit dates and two digit days

The code snip below saves information to disk. However on a date like
Jan 6, 2012 it saves the file name as "201216...." and I would like it
to be "20120106...." with a two digit month and a two digit day. Is it
possible to modify the code below so that it will do this? Thanks.


'Save the file
Range("A2").Select
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\g701942\My Documents\Supplier
Resource\" & Year(x) & Month(x) & Day(x) & " Weekly Supp Res-Ind Contr
List-full.xls" _
, FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Two digit dates and two digit days

hi John,

y = 2012
m = 1
d = 6
dt = Format(DateSerial(y, m, d), "yyyymmdd")
sFileName = "C:\Documents and Settings\g701942\My Documents\SupplierResource\" & dt & " Weekly Supp Res-Ind ContrList-full.xls"



--
isabelle



Le 2012-01-13 13:47, John Menken a écrit :
The code snip below saves information to disk. However on a date like
Jan 6, 2012 it saves the file name as "201216...." and I would like it
to be "20120106...." with a two digit month and a two digit day. Is it
possible to modify the code below so that it will do this? Thanks.


'Save the file
Range("A2").Select
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\g701942\My Documents\Supplier
Resource\"& Year(x)& Month(x)& Day(x)& " Weekly Supp Res-Ind Contr
List-full.xls" _
, FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Two digit dates and two digit days

Isabelle,
Thank you very much for the reply.
I was remiss in mentioning that the date that I am inserting into the
file name is what is collected from a message box.
The code that I use to collect a date is in Figure 1 below.

What I want to then do is insert it as part of the file name as
mentioned above. Your code works to give me the correct number of
digits but it confines it to a single date.
Re-reading my original post, I really wasn't clear in that regard. Is
there anyway to modify your code example to allow for this message box
date? Thank you.



Figure 1.

'Formats text in yellow
'These constants control which columns to check.
Const YOS = 13
Const Region = 11
Const SP1M90D = YOS + 2
Dim x As Variant, L0 As Long
x = InputBox("What is the report date?")
If IsDate(x) Then
For L0 = 2 To Cells.SpecialCells(xlCellTypeLastCell).Row
With Range("A" & CStr(L0) & ":W" & CStr(L0)).Interior
If Cells(L0, YOS).Value < 1 Then
If Cells(L0, SP1M90D).Value < CDate(x) Then
If Cells(L0, Region).Value = "NA" Then
.Color = vbYellow
Else
.Pattern = xlNone
End If
Else
.Pattern = xlNone
End If
Else
.Pattern = xlNone
End If
End With
Next
End If
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Two digit dates and two digit days

if i understand correctly,


x = InputBox("What is the report date?")
If IsDate(x) Then
dt = Format(DateSerial(Year(x), Month(x), Day(x)), "yyyymmdd")
sFileName = "C:\Documents and Settings\g701942\My Documents\SupplierResource\" & dt & " Weekly Supp Res-Ind ContrList-full.xls"


--
isabelle



Le 2012-01-17 13:07, John Menken a écrit :
Isabelle,
Thank you very much for the reply.
I was remiss in mentioning that the date that I am inserting into the
file name is what is collected from a message box.
The code that I use to collect a date is in Figure 1 below.

What I want to then do is insert it as part of the file name as
mentioned above. Your code works to give me the correct number of
digits but it confines it to a single date.
Re-reading my original post, I really wasn't clear in that regard. Is
there anyway to modify your code example to allow for this message box
date? Thank you.



Figure 1.

'Formats text in yellow
'These constants control which columns to check.
Const YOS = 13
Const Region = 11
Const SP1M90D = YOS + 2
Dim x As Variant, L0 As Long
x = InputBox("What is the report date?")
If IsDate(x) Then
For L0 = 2 To Cells.SpecialCells(xlCellTypeLastCell).Row
With Range("A"& CStr(L0)& ":W"& CStr(L0)).Interior
If Cells(L0, YOS).Value< 1 Then
If Cells(L0, SP1M90D).Value< CDate(x) Then
If Cells(L0, Region).Value = "NA" Then
.Color = vbYellow
Else
.Pattern = xlNone
End If
Else
.Pattern = xlNone
End If
Else
.Pattern = xlNone
End If
End With
Next
End If

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional format on first & last digit on 3 digit cell data caprey New Users to Excel 3 December 17th 08 05:24 PM
Convert 2 digit month to 4 digit years and months BB Excel Worksheet Functions 2 September 17th 06 09:33 PM
Color a single digit in a mult-digit number cell Phyllis Excel Discussion (Misc queries) 6 November 17th 05 12:46 AM
Tell users how to sort 5 digit and 9 digit zipcodes correctly aft. [email protected] New Users to Excel 1 February 18th 05 12:59 AM
When we enter a 16 digit number (credit card) the last digit chan. ceking Excel Discussion (Misc queries) 5 December 8th 04 11:45 PM


All times are GMT +1. The time now is 05:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"