Trying to find last row a column C

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Please see code below to find last row in column c in a Excel Table. How can I alter the code to work?
VBA Code:
LRow = tblDailyMail.Cells(Rows.Count, 3).End(xlUp).Row
VBA Code:
Sub Mouthly_DailyMail_Figurers()

    Dim CopyToRange As Range
    Dim PasteToRange As Range
    Dim Rng    As Range
    Dim Cell   As Range
    Dim LRow   As Long
    Dim wb     As Workbook
    Dim swb    As Workbook
    Dim sws    As Worksheet
    Dim ws     As Worksheet
    Dim tblDailyMail As Object
    Dim FileToOpen As Variant

    With Application
        .ScreenUpdating = False
        .Calculation = xlManual
        .DisplayAlerts = False
    End With
   
    Set swb = ActiveWorkbook
    Set sws = swb.Worksheets("Sheet")
    FileToOpen = ("S:\SALES\REPORTING\2023\Daily Mail.xlsx")
    Workbooks.Open FileToOpen
    Set wb = Workbooks("Daily Mail.xlsx")
    Set ws = wb.Worksheets("Daily Mail Update")
    Set CopyToRange = sws.Range("A2")
   
    With ws
        Set tblDailyMail = .ListObjects("Daily_Mail_Data")
        LRow = tblDailyMail.Cells(Rows.Count, 3).End(xlUp).Row
        Set PasteToRange = tblDailyMail.Range("C5:C" & LRow)
        For Each Cell In PasteToRange
            If Not WorksheetFunction.IsText(Cell.Value) Then
                Cell.Value = CopyToRange.Value
                Cell.Font.Name = "Arial"
                Cell.Font.Size = 11
            End If
        Next Cell
        .Range("H25") = CopyToRange
        .Range("I25") = sws.Range("B2")
    End With
   
    Call DalyMailUpdate
   
    Workbooks("Daily Mail.xlsx").Save
    '    Workbooks("Daily Mail.xlsx").Close
   
    With Application
        .ScreenUpdating = True
        .Calculation = xlAutomatic
        .DisplayAlerts = True
    End With
   
    MsgBox ("Daily Mail Mountly Figurers Updated")
   
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,

Since you are explicitly addressing a table, how about looping directly in that column?

VBA Code:
        'LRow = tblDailyMail.Cells(Rows.Count, 3).End(xlUp).Row
        'Set PasteToRange = tblDailyMail.Range("C5:C" & LRow)
        For Each Cell In tblDailyMail.listcolumns("columnCHeaderName").databodyrange
        .
        .
        Next
 
Upvote 0
Solution
Assuming by Column C you mean the 3rd column in the table then maybe try the ugly code below
VBA Code:
    With tblDailyMail
        LRow = Cells(.ListColumns(3).Range.Rows.Count + .HeaderRowRange.Row - 1, .ListColumns(3).Range.Column).End(xlUp).Row
    End With
 
Upvote 0
Hi,

Since you are explicitly addressing a table, how about looping directly in that column?

VBA Code:
        'LRow = tblDailyMail.Cells(Rows.Count, 3).End(xlUp).Row
        'Set PasteToRange = tblDailyMail.Range("C5:C" & LRow)
        For Each Cell In tblDailyMail.listcolumns("columnCHeaderName").databodyrange
        .
        .
        Next
This works thanks
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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