PDA

View Full Version : making calculation on named range col but returning col number total



VISHAL120
08-17-2010, 07:09 AM
Hi all I am actually making a calculation on vba with a name ranged for column and instead of calculating the values of the column it’s calculating the column number.

Here is the example col. C is named Tnumber and col E is Snum and Col G is total.
If value of Col C is 10 and Col E 20 we shall have 30 on col G but I am having 8 as number( its calculating the col number 3 + 5).

thanks to help me to solve this vba code.


Please find attaché the sample file for better idea.

Bob Phillips
08-17-2010, 09:46 AM
Sub CALCULATION_TXT()
Dim FNUM_COL As Integer
Dim SNUM_COL As Integer
Dim TOTAL_COL As Integer
Dim CELL As Range

FNUM_COL = Range("TNUMBER").Column
SNUM_COL = Range("SNUM").Column
TOTAL_COL = Range("TOTAL").Column

Set CELL = Range("GET_TOT")

Do Until CELL.Offset(0, -4).Value = ""

CELL.Value = Cells(CELL.Row, FNUM_COL) + Cells(CELL.Row, SNUM_COL)
Set CELL = CELL.Offset(1, 0)
Loop
End Sub


but =C3+E3 is a ton simpler

VISHAL120
08-18-2010, 01:08 AM
hi xld,

Thanks you very much for the code.

VISHAL120
08-20-2010, 06:43 AM
Hi ,

Many thanks for the answer. can you please explain me how i can do same if i have to calculate same for several columns that is for example:
IF COL A IS ITEM , COL B IS PRICE, COL C ,D ,E IS QTY SOLD BY DAY.
THE TOTAL SOLD WILL BE AS FROM COL G, H, I.

THIS WILL MAKE PRICE X BY QTY SOLD BY DAY = TOTAL SOLD BY DAY.

i want to do it in VBA not By formula. I have tried several ways by using the same code posted from my previous question but in vain.

see attached file for example.

many thanks in advance for the help as i will need this code to continue my project.

Bob Phillips
08-20-2010, 07:48 AM
Sub CALCULATION_TXT()
Dim Lastrow As Long
Dim Lastcol As Long
Dim i As Long
Dim j As Long

With ActiveSheet

Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
Lastcol = .Cells(3, .Columns.Count).End(xlToLeft).Column

For i = 4 To Lastrow

For j = 7 To Lastcol

.Cells(i, j).Value = .Cells(i, "B").Value * .Cells(i, j - 4).Value
Next j
Next i
End With
End Sub

VISHAL120
08-21-2010, 01:01 AM
HI xld,

many thanks for your reply. please have you been able to see my previous thread "
using VBA instead of fomula in the sheet due to multiplie calculation".

thanks to give a hint of how i can start with the vb code.

VISHAL120
08-21-2010, 01:28 AM
hi ,

thanks can you please explain me how can i place a total on top of the column that has been calculated by VBA please. that is on col G,H,I