Two rebellious cells refuse to listen to code

Bagharmin

Board Regular
Joined
Nov 22, 2010
Messages
168
I have two cells that my code cannot seem to affect at all. The ONLY bit of code in my entire Sub that does anything with these two cells is below:

Code:
Range("B5").Value = Application.WorksheetFunction.Text(Dateone, "##/##/####")
    Range("B6").Value = Application.WorksheetFunction.Text(Datetwo, "##/##/####")

My code refers to nearly all the cells around those two in the same fashion (i.e., Range("B7").Value, Range("D5").Value, etc.) and changes their values in the way I intended, but my code can't touch B5 or B6. I can type in the cells manually and the values will NEVER change when I run the code. The cells aren't locked and the sheet isn't protected. I've even stepped through the code to verify that Dateone and Datetwo have actual valid values (they do), but nothing I do will make those values show in those two cells. Grrr.

I'm at my wit's end. Does anyone have any sort of suggestions or insight on what might be causing this?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You're not using sheet names in your Range object, any chance you have activated a different sheet and are writing the values to that sheet?

Try some simple troubleshooting by eliminating the .Text function, see if this works:

Range("B5").Value = "Test"
 
Upvote 0
"##/##/####" is not a valid format. Try, for example, "mm/dd/yyyy"
 
Upvote 0
You could also use VBA's Format function rather than Application.WorksheetFunction.Text, not much of a diff but shorter. :D

Code:
Range("A10").Value = Format(myDate, "mm/dd/yyyy")
 
Last edited:
Upvote 0
Sigh. Thanks, shg. Changing to m/d/yyyy did exactly what I wanted. Of course, now I'm kicking myself for not catching that. I had done pratically everything else, though I hadn't thought about assigning some other, non-date value to those two cells (thanks, ChrisM - I'll remember that next time I have to track down stuff like this).

And thanks, eblake. Shorter is sweeter in code and I'll have to remember your suggestion (assuming I remember not to use "#" in the format).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top