PC Review


Reply
Thread Tools Rate Thread

Calculating Column and off setting calculated value to another column

 
 
S Himmelrich
Guest
Posts: n/a
 
      1st Feb 2008
The code below is not calculating the correct column, which should be
"J", not L, where the results are place...not sure what I've done.

With wks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("J1", .Cells(.Rows.Count, "J").End(xlUp)) _
.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0


If myRng Is Nothing Then
MsgBox "no constants"
Exit Sub
End If


For Each myArea In myRng.Areas
myFormula = "=sum(r[-1]c:r[-" & myArea.Cells.Count & "]c)"
Set FormCell = myArea.Cells(myArea.Cells.Count).Offset(1,
0)
With FormCell
.FormulaR1C1 = myFormula
.Offset(0, 2).Value = .Value
.Offset(0, 2).Font.Bold = True
.FormulaR1C1 = ""
End With
Next myArea
End With
 
Reply With Quote
 
 
 
 
Leith Ross
Guest
Posts: n/a
 
      1st Feb 2008
On Feb 1, 10:09 am, S Himmelrich <himmelr...@gmail.com> wrote:
> The code below is not calculating the correct column, which should be
> "J", not L, where the results are place...not sure what I've done.
>
> With wks
> Set myRng = Nothing
> On Error Resume Next
> Set myRng = .Range("J1", .Cells(.Rows.Count, "J").End(xlUp)) _
> .Cells.SpecialCells(xlCellTypeConstants)
> On Error GoTo 0
>
> If myRng Is Nothing Then
> MsgBox "no constants"
> Exit Sub
> End If
>
> For Each myArea In myRng.Areas
> myFormula = "=sum(r[-1]c:r[-" & myArea.Cells.Count & "]c)"
> Set FormCell = myArea.Cells(myArea.Cells.Count).Offset(1,
> 0)
> With FormCell
> .FormulaR1C1 = myFormula
> .Offset(0, 2).Value = .Value
> .Offset(0, 2).Font.Bold = True
> .FormulaR1C1 = ""
> End With
> Next myArea
> End With


Hello S Himmelrich,

Your new range myRng is only 1 column wide. It holds the contents of
column "J". Your code below Offsets from this address to 2 columns
over. This places you back on the worksheet in column "L".

With FormCell
.FormulaR1C1 = myFormula
.Offset(0, 2).Value = .Value <-----------
.Offset(0, 2).Font.Bold = True <-----------
.FormulaR1C1 = ""
End With
Next myArea
End With

Sincerely,
Leith Ross
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating column A * column B = Results in another column jhun Microsoft Excel Worksheet Functions 2 30th Mar 2010 05:13 AM
Calculating column 'J' and offsetting result in column 'L' on nextblank row (continue to end of sheet) S Himmelrich Microsoft Excel Programming 10 6th Feb 2008 04:23 PM
DataGridView - refreshing calculated columns when move from column to column. Greg Microsoft C# .NET 1 30th May 2006 07:44 PM
Calculating totals in a column based on a lookup in another column Michael Wright via OfficeKB.com Microsoft Excel Worksheet Functions 1 15th Apr 2005 09:52 AM
Setting a column width of a Template column programatically =?Utf-8?B?Q29yZXlNYXM=?= Microsoft Dot NET 0 14th Mar 2005 03:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 PM.