How to perform a math equation to everything in a cell using vba not knowing how many rows I have

Ivn68

Board Regular
Joined
Aug 21, 2015
Messages
82
I have a number in column C and I need to divide by 60 and round up to nearest digit. I need to do that to all the cells in column C

Thanks for any help
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Are you wanting to replace the current value in column C, or put the result in a different column?
Are you starting on row 1, row 2, or some other row?
 
Upvote 0
Try this:
VBA Code:
Sub MyReplaceNum()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column C with data
    lr = Cells(Rows.Count, "C").End(xlUp).Row
    
'   Loop through all values in column C starting on row 1
    For r = 2 To lr
'       Check to see if number in column C
        If IsNumeric(Cells(r, "C")) Then
'           Replace value in column C
            Cells(r, "C").Value = Round(Cells(r, "C").Value / 60, 0)
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
OK, try this then:
VBA Code:
Sub MyReplaceNum()

    Dim lr As Long
    Dim r As Long
    Dim v As Double
    
    Application.ScreenUpdating = False
    
'   Find last row in column C with data
    lr = Cells(Rows.Count, "C").End(xlUp).Row
    
'   Loop through all values in column C starting on row 1
    For r = 2 To lr
'       Check to see if number in column C
        If IsNumeric(Cells(r, "C")) Then
            v = Cells(r, "C").Value
'           Replace value in column C
            Cells(r, "C").Value = Application.WorksheetFunction.RoundUp(v / 60, 0)
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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