Search code examples
excelvbacopy-paste

use value of last cell in last column of table to trigger macro vba


Been trying all kinds of things to get this to work and I cant figure it out. Using a table, I am trying to use VBA to take the value of the last cell in the last column (column H in my case), and if it is > 0 then copy the last cell in column C (which is not in the table range, its just a regular cell) to the next cell below. Any help would be greatly appreciated. This is the last missing piece of this puzzle to finish this workbook!I dont have enough reputation to post an image but more than willing to email the image or the workbook to whomever is willing to help.


Solution

  • Sub Test()
    
    Dim ws as Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<-- Update
    Dim lrH as Long, lac as Long
    
    lrH = ws.Range("H" & ws.Rows.Count).End(xlUp).Row
    
    If ws.Range("H" & lr) > 0 Then
        lrC = ws.Range("C" & ws.Rows.Count).End(xlUp).Row
        ws.Range("H" & lrH + 1).Value = ws.Range("C" & lrC)
    End If