PDA

View Full Version : check my code pls



lneilson
08-04-2008, 08:44 AM
hi all

this is my formula adding up each row and displaying the answer in the column with data +1 and works fine it goes 3 rows to far ive tried to manipulate it with no success
if it matters it should stop on row 80
i will attach part of my page so you can see the problem

thanks

lneilson





lngRowLast = 1

For intCounter = 1 To intColLast
lngRowTemp = Columns(intCounter).Cells(lngRowCount, 1).End(xlUp).Row
If lngRowTemp > lngRowLast Then
lngRowLast = lngRowTemp
End If
Next intCounter

For intCounter = 1 To lngRowLast
Columns(intColLast + 1).Cells(intCounter, 1).Formula = _
"=sum(A" & intCounter & ":" & Columns(intColLast).Cells(intCounter, 1).Address & ")"
Next intCounter

Bob Phillips
08-04-2008, 02:29 PM
Can you show us all of the code?

lneilson
08-06-2008, 07:08 AM
thanks for the reply I worked this one out

lneilson

Aussiebear
08-06-2008, 02:30 PM
Since you raised this issue as a thread, to which XLD has tried to assist you, then as a matter of respect, please post the "fix".

lneilson
08-06-2008, 03:24 PM
sorry didn't know

lneilson

'Get the last used column.
'Start looking in the last column.
For intCounter = intColCount To 1 Step -1
If Columns(intCounter).End(xlDown).Row < lngRowCount Then
intColLast = intCounter
blnFound = True
Exit For
ElseIf Columns(intCounter).End(xlDown).Row = lngRowCount Then
If Columns(intCounter).End(xlDown).Value <> vbNullString Then
intColLast = intCounter
blnFound = True
Exit For
End If
End If
Next intCounter

'Get the last used row within the collection of used columns.
lngRowLast = 1

For intCounter = 1 To intColLast
lngRowTemp = Columns(intCounter).Cells(lngRowCount, 1).End(xlUp).Row
If lngRowTemp > lngRowLast Then
lngRowLast = lngRowTemp - 2
End If
Next intCounter

For intCounter = 1 To lngRowLast
Columns(intColLast + 1).Cells(intCounter, 1).Formula = "=sum(A" & intCounter & ":" & Columns(intColLast).Cells(intCounter, 1).Address & ")"
Next intCounter

Aussiebear
08-07-2008, 12:29 AM
I'd like to thank you for having posted the fix. The reason for posting the 'fix' is that others who visit this forum may gain from your experience, should they have either the same or a very similar issue.

The more we can share. the greater the benefits to our community, and this should always be our aim.