Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 3
Default Formatting automatically filled cells

Hi everybody!

My problem is like this :

There is an Excel 2007 under Windows 7 (Version Home Premium, if it can be somehow helpful) file, including a worksheet with a region consisting of two adjacent columns. The left column A is supposed to contain some date values in European format (f.ex. "31.12.2006"), the right one (column B) contains some positive integers in standard formats.
Further, there is another cell (say 'AB1') with a formula "=MAX(B:B)", and one more cell (say 'AC1') with formula "=INDEX(A:A;MATCH(AB1;B:B;0))".
As long as I fill the data in the region 'A:B' manually, the both AB1 and AC1 display obediently what I hope to find there. For instance, if the highest integer from the column 'B:B' is 39000 while the corresponding date reads 11.01.2005, the value of the AB1 is 39000, and the AC1 shows 38667 (the date value from "11.11.2005").

If only I try to enter the same data pair using some user forms with two fields - for the date and for the integer, they appear properly in their designed positions in the array 'A:B'. The AB1 displays correctly the value 39000 (which is currently the real MAX(B:B)), however the AC1 reads now "11.11.2005" - though I need 38667 at this place.

What could cause this phenomen?

Any kindly advice would be highly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Formatting automatically filled cells

Hello,

It sounds to me like the userform is returning a string rather than a date. If you Dim a Date field for your userform, it may help. The code would read something like this:

Private Sub CommandButton1_Click()
Dim dDate As Date
dDate = TextBox1.Value
Sheet1.Range("A50000").End(xlUp).Offset(1, 0).Value = dDate
End Sub

Alternatively, you could look at using a function like "CDate" in VBA to coerce the number into a date format. Or maybe using the "DateValue" and "IsText" functions in Excel to convert the string version of the date to a numeric value. For example, Cell AC1 might be changed to:

=IF(ISTEXT(INDEX(A:A,MATCH(AB1,B:B,0))), DATEVALUE(INDEX(A:A,MATCH(AB1,B:B,0))), INDEX(A:A,MATCH(AB1,B:B,0)))

Good Luck,

Ben
  #3   Report Post  
Junior Member
 
Posts: 3
Default

Thank you, Ben!

The reason was indeed as you supposed : a string as the return value from the user form...
No sooner I modified my code - it was already doing !

Many kindly regards.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Formatting automatically filled cells

Glad to hear it works, and happy to help.

Ben
  #5   Report Post  
Member
 
Location: Bangalore
Posts: 41
Default

Quote:
Originally Posted by Locateur View Post
Hi everybody!

My problem is like this :

There is an Excel 2007 under Windows 7 (Version Home Premium, if it can be somehow helpful) file, including a worksheet with a region consisting of two adjacent columns. The left column A is supposed to contain some date values in European format (f.ex. "31.12.2006"), the right one (column B) contains some positive integers in standard formats.
Further, there is another cell (say 'AB1') with a formula "=MAX(B:B)", and one more cell (say 'AC1') with formula "=INDEX(A:A;MATCH(AB1;B:B;0))".
As long as I fill the data in the region 'A:B' manually, the both AB1 and AC1 display obediently what I hope to find there. For instance, if the highest integer from the column 'B:B' is 39000 while the corresponding date reads 11.01.2005, the value of the AB1 is 39000, and the AC1 shows 38667 (the date value from "11.11.2005").

If only I try to enter the same data pair using some user forms with two fields - for the date and for the integer, they appear properly in their designed positions in the array 'A:B'. The AB1 displays correctly the value 39000 (which is currently the real MAX(B:B)), however the AC1 reads now "11.11.2005" - though I need 38667 at this place.

What could cause this phenomen?

Any kindly advice would be highly appreciated.
Hi,

Is it fine for you to attach a sample.

Here are two suggestions that I have to make.

Are you making sure that the data type of the dates returned from your user form is right, i.e. If you are getting the date in a text box by default it becomes a string. You need to convert that string value to an integer before you put it back onto the sheet. Assuming that you are not doing this, you are actually getting a text value (11.11.2005) returned to the cell not the integer value 38667 which is why you are getting the text version of the value in AC1.

If the above is taken care of and you still face the issue.
To quickly fix the issue inside the VBA code for user form change the format of the cell that evaluates the value (AC1).

If you aren't sure of anything above, please let me know. Please provide a sample for me to rework and provide you with the correct results.

Thanks,
Prashant


  #6   Report Post  
Member
 
Location: Bangalore
Posts: 41
Thumbs up

Quote:
Originally Posted by jack_n_bub View Post
Hi,

Is it fine for you to attach a sample.

Here are two suggestions that I have to make.

Are you making sure that the data type of the dates returned from your user form is right, i.e. If you are getting the date in a text box by default it becomes a string. You need to convert that string value to an integer before you put it back onto the sheet. Assuming that you are not doing this, you are actually getting a text value (11.11.2005) returned to the cell not the integer value 38667 which is why you are getting the text version of the value in AC1.

If the above is taken care of and you still face the issue.
To quickly fix the issue inside the VBA code for user form change the format of the cell that evaluates the value (AC1).

If you aren't sure of anything above, please let me know. Please provide a sample for me to rework and provide you with the correct results.

Thanks,
Prashant
Hi There,

Apologies didn't note that Ben had already replied. The issue indeed was with the data type.

Nevertheless, happy to see your issue is resolved.
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
How to get info filled in automatically slgs_13 Excel Discussion (Misc queries) 2 January 23rd 10 01:29 PM
Printing a Page Automatically When All Cells are Filled Gerard Sanchez Excel Programming 7 February 27th 09 12:25 PM
Filled cells dont appear as filled SMILLS Excel Discussion (Misc queries) 6 October 18th 07 05:28 PM
How do I avoid fields being automatically filled in by default? jason New Users to Excel 1 June 15th 06 11:28 PM
I need formula that will automatically count the filled cells. Benar_Isais Excel Discussion (Misc queries) 2 November 15th 05 11:22 AM


All times are GMT +1. The time now is 09:16 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"