This code is trying to delete all times from cells so just show`s Date

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
431
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
This code say`s runtime error 13??

VBA Code:
Sub FormatCells()

    Dim wb     As Workbook
    Dim ws     As Worksheet
    Dim LRow   As Long
    Dim Rng    As Range
    Dim Cell   As Range
    Dim i      As Long

    Set wb = ActiveWorkbook
    Set ws = wb.Sheets("Sheet")
    LRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With
    
    With ws
        Set Rng = ws.Range("F2:F" & LRow)
    End With
        
        For i = 2 To LRow
            With Range("F" & i)
                .NumberFormat = "dd/mm/yyyy"
                .Value = DateValue(.Value)
            End With
        Next i
        
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Do you have any Text values in column F?

What happens if you click the Debug button?
Which line of code does it highlight?
When you hit debug, hover over the variable "i" in your code to see which row it is choking on, and look at the value in that row of column F.
 
Upvote 0
This is the code it highlights
VBA Code:
  .Value = DateValue(.Value)
It kicks up on row 2
 
Upvote 0
What exactly is in cell F2?
 
Upvote 0
The date and the time so i need the time to go.
19/10/2023 08:14:04
That works just fine for me.
Where is this data coming from? Is it an export or download from another location?
I wonder if it has some extra or special characters in there.

Enter this formula in any blank cell on your sheet, and tell me what it returns:
Excel Formula:
=ISNUMBER(F2)
If it returns false, it means that the entry is NOT a valid date/time entry, but is instead a Text entry.
 
Upvote 0
Yes data is from a program called Intact
Put this
VBA Code:
=ISNUMBER(F2)
in a cell says FALSE
 
Upvote 0
In addition to the formula I asked you to try in my previous post, see what these two formulas return:
Excel Formula:
=LEN(F2)
and
Excel Formula:
=CODE(MID(F2,11,1))

Tell us what these return. They will help us to identify any extra or special characters that may be causing issues.
 
Upvote 0
In addition to the formula I asked you to try in my previous post, see what these two formulas return:
Excel Formula:
=LEN(F2)
Says 0
and
Excel Formula:
=CODE(MID(F2,11,1))
Says #VALUE

Tell us what these return. They will help us to identify any extra or special characters that may be causing issues.
 
Upvote 0
That is impossible!

Up above, you said that you have the following value in cell F2:
Rich (BB code):
19/10/2023 08:14:04

If that is indeed true, there is NO way this formula can return 0:
Excel Formula:
=LEN(F2)

That says there is NOTHING in cell F2.

So what is it that you aren't telling me?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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