[RESOLVED] Help needed with Variable Constant assigning
Guys,
I have an issue I hope you can offer assistance on.
I am trying to define a variable to maintain a number between 01 and 52,
but I want to retain the two digit format, ie... it needs to be 01, - 09.
The purpose of this is to join with another variable to display a Year and Wk format.
This will then be outputted into a cell, and a for next function used to populate subsequent cells with the same value + 1.
Using a String constant I have been able to retain 01, 02 etc, but when my For Next function then populates the cells I lose the 2 digit format, and it revertes to 1, 2, 3 etc.
I have tried both Byte and Long constants but to the same effect.
Below is my code that I am using, any assistance would be most appreciated.
Dim strWk As String
Dim strYear As Long
Dim strProduct As Long
strWk = InputBox("Please enter the current Financial week ? (example: 01,21,52)")
strYear = InputBox("Please enter the current Financial year ? (example: 1999, 2008, 2010)")
strProduct = InputBox("Please enter the product number that you want to view ? (example: 2205, 83312, 5)")
Range("c6").Value = (strWk)
Range("d6").Value = (strYear)
Range("c10").Value = (strProduct)
Dim strFY As String
strFY = strYear & strWk
Range("c15").Value = (strFY)
Range("c15").Select
For x = 1 To 51
ActiveCell.Offset(0, 1).Activate
strWk = strWk + 1
strFY = strYear & strWk
ActiveCell.Value = (strFY)
If strWk = 52 Then strYear = strYear + 1
If strWk = 52 Then strWk = 0
Next x
Re: Help needed with Variable Constant assigning
to keep the format in the cell you need to set the format of the cell to text, before inserting the data, you can do this either manually or by code
Range("a:a").numberformat = "@"
Re: Help needed with Variable Constant assigning
Quote:
Originally Posted by westconn1
to keep the format in the cell you need to set the format of the cell to text, before inserting the data, you can do this either manually or by code
Range("a:a").numberformat = "@"
West Conn,
It is not the format of the cells that is the issue, as you can see from my code, I change the variable strWk to + 1 each time I use the offset function in the For next loop, this is causng the issue, as each time the variable changes it loses the two digit integrity if the result is less than 10.
In other words, the user can input 01, and the initial output will be 01, but when the variable changes + 1, it now changes to 2 and loses the two digit integrity.
How can I get around this?
Re: Help needed with Variable Constant assigning
try
strWk = format(strWk + 1,"00")
Re: Help needed with Variable Constant assigning
Quote:
Originally Posted by westconn1
try
strWk = format(strWk + 1,"00")
West,
Thanks that worked a treat. :D
SJ