Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Variable Selection Summation

I have a macro that utilizes Excel AND Access, when the final report pops out
of Access, there is some more formatting that needs to be done in excel. The
# of columns vary based on # of locations. I want to do some calculations of
the cells going across and am trying to find a way to have it select the
range and sum for example. Here is what I'm looking at:

ColumnA ColumnB ColumnC ColumnD ColumnE ColumnF
Part# PQ Loc1OH Loc2OH Loc3OH TOTAL
AAAA 5 1 2 4 7
<-- This Sum is the ?


I can get it to find the last column with:

Dim LastColumn As Long
LastColumn = Range("A1").End(xlToRight).Column
Cells(LastColumn + 1).Select

I cannot get it to select the columns before it to sum them within that
selection.

Also I have it set the MyValue to the number of locations right before that,
so I have that number. I was trying to use IF/Then Statements with looping
around between Line1: Line2: etc. But I couldn't figure out a way to select
the cells over and sum them in the last column.

However, I can't get it to Select Column C,D,E and sum them in F properly.
I could create a hundred code sections and have it jump around in the macro
according to Location numbers, but that would be terribly cumbersome and
long. It will always start with Column C and sum over a # of columns based
on locations. Is there any way to Have it do what I am asking for? Am I
Making Sense? Thanks for any help.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Variable Selection Summation

does it fit?

Sub test()
Dim LastColumn As Long
Dim LastRow As Long
Dim RowIndex As Long
Const StartColumn = 3
Const StartRow = 2
Dim ColumnDistance As Long

LastColumn = Range("A1").End(xlToRight).Column + 1
ColumnDistance = LastColumn - StartColumn
LastRow = Range("A1").End(xlDown).Row

For RowIndex = StartRow To LastRow
Cells(RowIndex, LastColumn).FormulaR1C1 = "=SUM(RC[-" &
ColumnDistance & "]:RC[-1])"
Next RowIndex
End Sub

"bodhisatvaofboogie" wrote:

I have a macro that utilizes Excel AND Access, when the final report pops out
of Access, there is some more formatting that needs to be done in excel. The
# of columns vary based on # of locations. I want to do some calculations of
the cells going across and am trying to find a way to have it select the
range and sum for example. Here is what I'm looking at:

ColumnA ColumnB ColumnC ColumnD ColumnE ColumnF
Part# PQ Loc1OH Loc2OH Loc3OH TOTAL
AAAA 5 1 2 4 7
<-- This Sum is the ?


I can get it to find the last column with:

Dim LastColumn As Long
LastColumn = Range("A1").End(xlToRight).Column
Cells(LastColumn + 1).Select

I cannot get it to select the columns before it to sum them within that
selection.

Also I have it set the MyValue to the number of locations right before that,
so I have that number. I was trying to use IF/Then Statements with looping
around between Line1: Line2: etc. But I couldn't figure out a way to select
the cells over and sum them in the last column.

However, I can't get it to Select Column C,D,E and sum them in F properly.
I could create a hundred code sections and have it jump around in the macro
according to Location numbers, but that would be terribly cumbersome and
long. It will always start with Column C and sum over a # of columns based
on locations. Is there any way to Have it do what I am asking for? Am I
Making Sense? Thanks for any help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Variable Selection Summation

Maybe something like:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim LastCol As Long
Dim LastRow As Long
Dim FirstRow As Long
Dim FirstCol As Long

Set wks = Worksheets("sheet1")

With wks

FirstRow = 2 'data starts in row 2?
FirstCol = 3 'data starts in column C

'I like to come from the right
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
'and from the bottom towards the top
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.Cells(FirstRow, LastCol + 1).Resize(LastRow - FirstRow + 1, 1) _
.FormulaR1C1 _
= "=sum(rc" & FirstCol & ":rc[-1])"
End With

End Sub


bodhisatvaofboogie wrote:

I have a macro that utilizes Excel AND Access, when the final report pops out
of Access, there is some more formatting that needs to be done in excel. The
# of columns vary based on # of locations. I want to do some calculations of
the cells going across and am trying to find a way to have it select the
range and sum for example. Here is what I'm looking at:

ColumnA ColumnB ColumnC ColumnD ColumnE ColumnF
Part# PQ Loc1OH Loc2OH Loc3OH TOTAL
AAAA 5 1 2 4 7
<-- This Sum is the ?

I can get it to find the last column with:

Dim LastColumn As Long
LastColumn = Range("A1").End(xlToRight).Column
Cells(LastColumn + 1).Select

I cannot get it to select the columns before it to sum them within that
selection.

Also I have it set the MyValue to the number of locations right before that,
so I have that number. I was trying to use IF/Then Statements with looping
around between Line1: Line2: etc. But I couldn't figure out a way to select
the cells over and sum them in the last column.

However, I can't get it to Select Column C,D,E and sum them in F properly.
I could create a hundred code sections and have it jump around in the macro
according to Location numbers, but that would be terribly cumbersome and
long. It will always start with Column C and sum over a # of columns based
on locations. Is there any way to Have it do what I am asking for? Am I
Making Sense? Thanks for any help.



--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Variable Selection Summation

Worked Great!!! Thanks. I figured out a solution that took a few seconds
longer for it to complete, your method is much more efficient, Thanks again!!!



"Dave Peterson" wrote:

Maybe something like:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim LastCol As Long
Dim LastRow As Long
Dim FirstRow As Long
Dim FirstCol As Long

Set wks = Worksheets("sheet1")

With wks

FirstRow = 2 'data starts in row 2?
FirstCol = 3 'data starts in column C

'I like to come from the right
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
'and from the bottom towards the top
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.Cells(FirstRow, LastCol + 1).Resize(LastRow - FirstRow + 1, 1) _
.FormulaR1C1 _
= "=sum(rc" & FirstCol & ":rc[-1])"
End With

End Sub


bodhisatvaofboogie wrote:

I have a macro that utilizes Excel AND Access, when the final report pops out
of Access, there is some more formatting that needs to be done in excel. The
# of columns vary based on # of locations. I want to do some calculations of
the cells going across and am trying to find a way to have it select the
range and sum for example. Here is what I'm looking at:

ColumnA ColumnB ColumnC ColumnD ColumnE ColumnF
Part# PQ Loc1OH Loc2OH Loc3OH TOTAL
AAAA 5 1 2 4 7
<-- This Sum is the ?

I can get it to find the last column with:

Dim LastColumn As Long
LastColumn = Range("A1").End(xlToRight).Column
Cells(LastColumn + 1).Select

I cannot get it to select the columns before it to sum them within that
selection.

Also I have it set the MyValue to the number of locations right before that,
so I have that number. I was trying to use IF/Then Statements with looping
around between Line1: Line2: etc. But I couldn't figure out a way to select
the cells over and sum them in the last column.

However, I can't get it to Select Column C,D,E and sum them in F properly.
I could create a hundred code sections and have it jump around in the macro
according to Location numbers, but that would be terribly cumbersome and
long. It will always start with Column C and sum over a # of columns based
on locations. Is there any way to Have it do what I am asking for? Am I
Making Sense? Thanks for any help.



--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do summation of unique counts based on another variable? Chin Huat Excel Worksheet Functions 3 August 20th 09 05:57 PM
Variable range column summation and averaging Tom Excel Discussion (Misc queries) 2 March 15th 08 04:10 AM
How do I perform summation over variable areas? Pithecanthropus Excel Discussion (Misc queries) 1 August 8th 07 07:02 PM
Variable for column selection Mats W. Excel Programming 2 July 14th 05 09:17 AM
VBA code to perform summation and product summation 21MSU[_2_] Excel Programming 4 May 17th 04 07:19 PM


All times are GMT +1. The time now is 01:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"