The follow code should work -- I am assuming that the first row has headings.
Public Sub TimeStuff()Dim EACC As IntegerEACC = 0Range("EA1").ActivateDo EACC = EACC + 1 ActiveCell.Offset(1, 0).ActivateLoop Until ActiveCell.Value = ""Range("DZ2").FormulaR1C1 = "=TIME(INT(RC[1]/100),MOD(RC[1],100),0)"Range("DZ2").AutoFill Destination:=Range("DZ2:DZ" & EACC)Range("DZ2").ActivateEnd Sub
Very weird -- I just tried it on my system with success. What version of Excel are you using? What is the format for those target cells. They start off as general on mine and are switched to custom h:mm AM/PM Any change that you could post the spreadsheet? Just having the DZ and EA columns would work for testing. I find that when I work with made up data that everything works until I get the real data.
I just saved the sheet and the values updated correctly. All the formulas were showing correctly in the DZ cells but only updated when saved. I imagine there is an simple line of code to save the sheet?
Formula in DZ3 was correct =TIME(INT(EA3/100),MOD(EA3,100),0)
I added this line to the end of your code and it updated correctly,
Columns ("DZ") .Formula = Columns ("DZ") .Formula
Microsoft Excel
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
Open in new window
There is probably a more elegant way to determine number of rows.
Tom