Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Cols - Excel

Status
Not open for further replies.

Trudye

Programmer
Sep 4, 2001
932
US
I am trying to add two cols (C/D) and place the sum in col G for an variable number of rows.

I tried running a macro but the code it rendered was not useful (or at least it made no sense to me).

I ck'd FAQ but most of the hits were for Access.

Can anyone point me to a useful thread?
 


Hi,

If you want help with the code, please post in VBA Visual Basic for Applications (Microsoft) forum707.

Are you Adding columns (inserting columns) or are you adding VALUES in 2 columns to display in a third?

Where is your formula?

Skip,

[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount! [tongue]
 
Trudye,

If you are simply adding C2 and D2, then place
[COLOR=blue white]=C2+D2[/color]
in G2. Copy down as far as needed.

If, on the other hand, you are adding all values in columns C& D, then use this formula:
[COLOR=blue white]=sum(C:D)[/color]

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 

Thanks to both of you for responding. Skip, I thought this was the default Excel forum since there is not official Excel forum. I thought the VBA forum was for Access only.

John What will happend when a null value exists in one of the cells?

Trudye
 
Also how to assign the values to col G ?

worksheets("sheet1").range("G").value =sum(C:D)

 
What will happend when a null value exists in one of the cells?"
Why don't you try it and see? If you don't like the results then post back with the precise problem.

Try out:
=C5+D5
=SUM(C5:D5)
=SUM(C6,D6)
The second two handle cases where one of the cells has text in it differently to the first.

In Help search for "Fill Down" or "Fill handle" though this only works if you have data in every adjacent cell.

Hope this helps you,


Gavin
 
Trudye said:
What will happend when a null value exists in one of the cells?
Null + 4 = 4. So you can just sum the entire columns without worrying about how many rows you have.

Trudye said:
Also how to assign the values to col G ?

worksheets("sheet1").range("G").value =sum(C:D)
My solution does not use any code. Just copy and paste the formula [COLOR=blue white]=sum(C:D)[/color] into cell G2.

If you need to use code, then you should post in forum707, VBA Visual Basic for Applications (Microsoft). That is not Access-specific. VBA can be used in Excel, Access or Word. Any questions for VBA belong in forum707.

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 

A file will be downloaded monthly that will use this code, so it has to be in the code and not in the workbook. The first statment in the Excel module will pull the downloaded Excel file in, and then run the code.

Is there a way to do it with code?
 
Trudye said:
Is there a way to do it with code?
Yes. Yes there is.

A great place to start would be to use the macro recorder and try what I suggested.

If you still need help, another great idea would be to post in the appropriate forum! [wink]

forum707

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top