Loop to divide last cell in two different columns

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
34
Hello,

I'm trying to loop through a workbook and calculate the percentage between two values that are sums of their respective columns in each worksheet. I want to divide column Q last row value by R's last row value as well as T last row divided by R last row. My code is working, but the only value being polulated is the divided value in the last worksheet in the workbook. So the same values are being populated in each sheet, except I want each to be calculated individually.

http://prntscr.com/p3uzwk
http://prntscr.com/p3uzih
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I forgot to attach the code! but I figured it out.

Sub WRKShtLoo1pFormat()

'Loops through every worksheet

Dim ws As Worksheet


Dim lastRowInColQ As Long
Dim lastRowInColR As Long
Dim lastRowInColT As Long

Dim totPointsRowR As Long
Dim totPointsRowT As Long
Dim totPointsRowQ As Long

For Each ws In Worksheets




With ws.Range("A" & Rows.Count).End(xlUp).Offset(0)

.Offset(5, 10).Value = "GENERAL IPR PERCENTAGE"

If ws.Range("Q" & Rows.Count).End(xlUp).Value <> 0 Then
.Offset(5, 11).Value = ws.Range("Q" & Rows.Count).End(xlUp).Value / ws.Range("R" & Rows.Count).End(xlUp).Value * 100

.Offset(7, 10).Value = "GENERAL IDR PERCENTAGE"

If ws.Range("T" & Rows.Count).End(xlUp).Value <> 0 Then
.Offset(7, 11) = ws.Range("T" & Rows.Count).End(xlUp).Value / ws.Range("R" & Rows.Count).End(xlUp).Value * 100

End If
End If


End With

Next ws





End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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