R
Reha
Hello All,
I found this macro from the Groups which sums Columns according to the
Value of 'x'.
Sub test() ' Macro to Sum Columns
Dim lrow As Long, x As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
lrow = ws.Cells(Rows.Count, "A").End(xlUp).Offset(1).Row
' sum the columns - change x according to your needs
For x = 1 To 2
lrow = ws.Cells(Rows.Count, x).End(xlUp).Offset(1).Row
If Application.Sum(Range(ws.Cells(2, x),
ws.Cells(lrow, x))) > 0 Then
With ws.Cells(lrow, x)
.Formula = "=Sum(" & Range(ws.Cells(2,
x), ws.Cells(lrow - 1, x)).Address(0, 0) & ")"
.NumberFormat = "#,###"
End With
End If
Next
End Sub
My requirement is to search for a text appearing in Sheet1 and Sum
adjacent Columns.
No. of Rows would be varying.
For eg: lookup the text 'Grade' and Sum adjacent two columns.
If the text 'Grade' appears in
Column B then Sum Col C and D...
if in F then Sum Columns G and H...
if in T then Sum Columns U and V
and so on...
Any help would be greatly appreciate.
Thanks and regards
Reha
I found this macro from the Groups which sums Columns according to the
Value of 'x'.
Sub test() ' Macro to Sum Columns
Dim lrow As Long, x As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
lrow = ws.Cells(Rows.Count, "A").End(xlUp).Offset(1).Row
' sum the columns - change x according to your needs
For x = 1 To 2
lrow = ws.Cells(Rows.Count, x).End(xlUp).Offset(1).Row
If Application.Sum(Range(ws.Cells(2, x),
ws.Cells(lrow, x))) > 0 Then
With ws.Cells(lrow, x)
.Formula = "=Sum(" & Range(ws.Cells(2,
x), ws.Cells(lrow - 1, x)).Address(0, 0) & ")"
.NumberFormat = "#,###"
End With
End If
Next
End Sub
My requirement is to search for a text appearing in Sheet1 and Sum
adjacent Columns.
No. of Rows would be varying.
For eg: lookup the text 'Grade' and Sum adjacent two columns.
If the text 'Grade' appears in
Column B then Sum Col C and D...
if in F then Sum Columns G and H...
if in T then Sum Columns U and V
and so on...
Any help would be greatly appreciate.
Thanks and regards
Reha