Simple macro to find the next blank column in the range

0

Hi Guys,

I have data for same month in multiple columns in a continuous range.

Each month range is separated by a blank column.

What I want is a macro that find the next blank cell in column starting cell B10 and autosum the columns preceding the blank cell.

I want autosum in highlighted columns in yellow (must be a loop).



I started writing the code but stuck:

Sub sum()
ActiveSheet.Range("b10").Select
Selection.Columns.End(xlToRight).Offset(0, 1).Select
ActiveCell.Value = "=Sum(columns.end (xltoleft)"



End Sub


Many thanks 
Sophia
Answer
Discuss

Answers

0

Try this macro:

Sub sum_macro()

last_row = Range("A" & Rows.Count).End(xlUp).Row


For cur_row = 10 To last_row

    last_col = Cells(cur_row, Columns.Count).End(xlToLeft).Column

    Cells(cur_row, last_col + 1).Formula = "=SUM(" & Range(Cells(cur_row, 1), Cells(cur_row, last_col)).Address(False, False) & ")"

Next cur_row

End Sub

You had a few pieces here and there, but keep practicing and you will understand macros in no time!

Discuss

Answer the Question

You must create an account to use the forum. Create an Account or Login