S
sgl
Hi all,
I need to add a range of cells with VBA whose length
which varies each time.
Within my code I have written the following. Although I
can locate the last cell address within the range the sum
function does not return the value. Can someone please
correct my code or tell me what i am doing wrong.
' Total Debit and Credit columns
Dim TtlDr As Double
Dim TtlCr As Double
Dim LastRowDr As Range
Dim LastRowCr As Range
Set LastRowDr = ActiveWorkbook.Worksheets
("Datasheet").Range("D65536").End(xlUp).Offset(-1, 2)
Set LastRowCr = ActiveWorkbook.Worksheets
("Datasheet").Range("D65536").End(xlUp).Offset(-1, 3)
TtlDr = Application.WorksheetFunction.Sum
(ActiveWorkbook.Worksheets("Datasheet").Range("F8", Range
(LastRowDr.Address)))
TtlCr = Application.WorksheetFunction.Sum
(ActiveWorkbook.Worksheets("Datasheet").Range("G8", Range
(LastRowCr.Address)))
DstRng.Cells(DstR, 6).Value = TtlDr
DstRng.Cells(DstR, 6).Font.Bold = True
DstRng.Cells(DstR, 6).BorderAround Weight:=xlThin
DstRng.Cells(DstR, 7).Value = TtlCr
DstRng.Cells(DstR, 7).Font.Bold = True
DstRng.Cells(DstR, 7).BorderAround Weight:=xlThin
Many thanks in advance
I need to add a range of cells with VBA whose length
which varies each time.
Within my code I have written the following. Although I
can locate the last cell address within the range the sum
function does not return the value. Can someone please
correct my code or tell me what i am doing wrong.
' Total Debit and Credit columns
Dim TtlDr As Double
Dim TtlCr As Double
Dim LastRowDr As Range
Dim LastRowCr As Range
Set LastRowDr = ActiveWorkbook.Worksheets
("Datasheet").Range("D65536").End(xlUp).Offset(-1, 2)
Set LastRowCr = ActiveWorkbook.Worksheets
("Datasheet").Range("D65536").End(xlUp).Offset(-1, 3)
TtlDr = Application.WorksheetFunction.Sum
(ActiveWorkbook.Worksheets("Datasheet").Range("F8", Range
(LastRowDr.Address)))
TtlCr = Application.WorksheetFunction.Sum
(ActiveWorkbook.Worksheets("Datasheet").Range("G8", Range
(LastRowCr.Address)))
DstRng.Cells(DstR, 6).Value = TtlDr
DstRng.Cells(DstR, 6).Font.Bold = True
DstRng.Cells(DstR, 6).BorderAround Weight:=xlThin
DstRng.Cells(DstR, 7).Value = TtlCr
DstRng.Cells(DstR, 7).Font.Bold = True
DstRng.Cells(DstR, 7).BorderAround Weight:=xlThin
Many thanks in advance