I'm doing a macro to calculate cell values from a given range (starting cell to ending cell) and iterate through the cells until it finds a null cell (no value in it).
So the workflow should be:
- Starting cell (user defined);
- Ending cell (user defined);
- Loop through values until empty cell is found. If empty cell is found, next column (Note: I'm assuming that a empty cell is break of the column);
- Loop through columns until end cell is reached;
- If ending cell is reached, unless it's empty, loop through column until empty cell is found;
- Stop the program.
It should also get the values from the active cell and calculate the sum when it changes column (for now it just an idea, not main problem).
The problem here that I'm having is that by allowing the user to choose it ending I'm stuck at stopping the loop when it reaches that ending cell.
This is what I've done so far (Note: No error handling on input yet, to be added later):
Sub test01()
Dim startCell As Variant
Dim endCell As Variant
Range("A1").Select ' Starting cell position
startCell = Application.InputBox("A", "A", , , , , Type:=8) 'Start of range
endCell = Application.InputBox("B", "B", , , , , Type:=8) 'End of range
Do
If IsEmpty(ActiveCell) Then
ActiveCell.EntireColumn.Select
ActiveCell.Offset(0, 1).Select
Else
'Calculate data
ActiveCell.Offset(1, 0).Select
If ActiveCell.Column And ActiveCell.Row = endCell Then
Exit Do
End If
End If
Loop
End Sub
Any sugestions on what I'm doing wrong and ways to improve it? Thanks :)
PS. New with vba.