Results 1 to 2 of 2

Thread: Loop to divide last cell in two different columns
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Nov 2018
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Loop to divide last cell in two different columns

    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

  2. #2
    New Member
    Join Date
    Nov 2018
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Loop to divide last cell in two different columns

    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •