Excel - Use VBA to modify a cell based on the sum of other cells in the row. Loop
In my sheet I would like to hit a button and loop through a series o开发者_高级运维f rows and change A3 to contain "x" if sum(C3:F3) = 0 and "" if sum(C3:F3) > 0 then move to row 4, then row 5 then row 6, etc.
Any help would be appreciated.
Thanks.
do you mean in row 3 use the sum of row 3, in row 4 use the sum of row 4 and put the x also in row 4 and so on?
The easiest is to just use either use the index function (use the easy one where the index is the row into your array, or just write a little program that copies the formulas down, then you have everything automatically correct thanks to the relative references.
If you would post your code / show the row/column setup one could easily answer with the code and/or formulas
No need for VBA. Put this formula in A3 and fill down:
=IF(SUM(C3:F3)=0,"x","")
You can use spreadsheet functions in VBA code, like so:
Dim Res As Variant
Worksheets("MySheet").Activate
Res = Application.WorksheetFunction.SUM("A1:C100")
The worksheet function will act on the currently active worksheet, so be sure to set that first.
精彩评论