![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Detroit
Posts: 792
|
How do I create a macro that makes calculations starting just after a row (with "Qty" in col A) UP to a row that contains a unique entry called "Grand Total"
(in say Column B) Calculation are like: G8 = a8*e8 and H8 = a8*e8-d8 etc |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Location: Greenwood, SC
Posts: 677
|
I like to use the Cells array for things like this.
dim i as integer dim bStart as Boolean bStart = False For i = 1 to 100 if cells(i,2).value = "Grand Total" then Exit For if bStart = True then Cells(i,7).value = cells(i,1).value * cells(i,5).value Cells(i,8).value = cells(i,7).value - cells(i,4).value etc. End If if cells(i,1).value = "Qty" then bStart = True Next Hope this helps... K |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Location: Detroit
Posts: 792
|
Thanks,
Here is what I created, its errors at the ??? ----- Dim i As Integer Dim bStart As Boolean bStart = False For i = 1 To 100 If Cells(i, 2).Value = "Grand Total" Then Exit For ' define end If bStart = True Then If Cells(i, 1).Value <> 0 Then ' insure there is a qty If Cells(i, Cells(i, 10).Value = Cells(i, 1).Value * Cells(i, 5).Value ElseIf Cells(i, Cells(i, 10).Value = Cells(i, 1).Value * (Cells(i, 5).Value - Cells(i, 5).Value * Cells(i, ElseIf Cells(i, 9) > 0 Then ' use specified value in col J - Unit selling price Cells(i, 10).Value = Cells(i, 1).Value * Cells(i, 10).Value End If End If End If If Cells(i, 1).Value = "Qty." Then bStart = True ' define start Next End Sub |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Location: Detroit
Posts: 792
|
That funkie character is an 8 (number eight) no idea why the display...
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Location: Detroit
Posts: 792
|
Also need to account for a "blank" field and treat it as if a "0" had been entered
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|