Change cell values with VBA code

AirOliver

New Member
Joined
Apr 16, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have a sheet with values in a column (say J) and I would like to convert those values to minutes.
Normally I could just insert a new column to the right (column K) and create a formula (=TEXT(J2/86400; "tt:mm:ss"), fill downwards, so it converts the values in each cell to minutes and seconds and format the cells to (tt:mm:ss). Then convert the new column (K) to the value of the formula, so I can delete the original column (J). I can't do this manually every time and macro didn't work for me.

That's why I want this to be done easily with a VBA code when pressing a button.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
VBA Code:
Sub do_It()
For r = 2 To Cells(Rows.Count, "J").End(xlUp).Row
    Cells(r, "K") = Format(Cells(r, "J") / 86400, "hh:mm:ss")
Next r
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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