PC Review


Reply
Thread Tools Rate Thread

Calcutate SUM of column in first blank row

 
 
PVANS
Guest
Posts: n/a
 
      18th Mar 2010
Hi All,

Hope someone can help me with this.

I am trying to find a method of finding the first blank row on a worksheet
and perform a sum calculation for column B:

example:
Before
A B
ww ww
x 1
x 2
x 5
x 6

After
ww ww
A B
x 1
x 2
x 5
x 6
14

I have code to find the first blank row:
Dim NextRow As Long
NextRow = Range("B65536").End(xlUp).Row + 1
Cells(NextRow, 2) = "test"

But of course, I don't want it to say test, but insteade calulate the sum of
all values in the column from B2 down (B1 has heading)

Thank you, really appreciate any help
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      18th Mar 2010
Hi,

Like this

LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"PVANS" wrote:

> Hi All,
>
> Hope someone can help me with this.
>
> I am trying to find a method of finding the first blank row on a worksheet
> and perform a sum calculation for column B:
>
> example:
> Before
> A B
> ww ww
> x 1
> x 2
> x 5
> x 6
>
> After
> ww ww
> A B
> x 1
> x 2
> x 5
> x 6
> 14
>
> I have code to find the first blank row:
> Dim NextRow As Long
> NextRow = Range("B65536").End(xlUp).Row + 1
> Cells(NextRow, 2) = "test"
>
> But of course, I don't want it to say test, but insteade calulate the sum of
> all values in the column from B2 down (B1 has heading)
>
> Thank you, really appreciate any help

 
Reply With Quote
 
Domenick
Guest
Posts: n/a
 
      18th Mar 2010
Mike,

Can you explain what the "B" represents in your first line? Doesnt the
argument for Cells have to be (<integer>,<integer>)? I'm confused.

Thanks.

-Dom

"Mike H" wrote:

> Hi,
>
> Like this
>
> LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "PVANS" wrote:
>
> > Hi All,
> >
> > Hope someone can help me with this.
> >
> > I am trying to find a method of finding the first blank row on a worksheet
> > and perform a sum calculation for column B:
> >
> > example:
> > Before
> > A B
> > ww ww
> > x 1
> > x 2
> > x 5
> > x 6
> >
> > After
> > ww ww
> > A B
> > x 1
> > x 2
> > x 5
> > x 6
> > 14
> >
> > I have code to find the first blank row:
> > Dim NextRow As Long
> > NextRow = Range("B65536").End(xlUp).Row + 1
> > Cells(NextRow, 2) = "test"
> >
> > But of course, I don't want it to say test, but insteade calulate the sum of
> > all values in the column from B2 down (B1 has heading)
> >
> > Thank you, really appreciate any help

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      18th Mar 2010
> Can you explain what the "B" represents in your first line?

LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row

The B represent column B and no the 2 values for 'CELL' don't have to be
integer

Cells(1, "B").Value = "wwwww"
is the same as
Cells(1, 2).Value = "wwwww"

HTH


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Domenick" wrote:

> Mike,
>
> Can you explain what the "B" represents in your first line? Doesnt the
> argument for Cells have to be (<integer>,<integer>)? I'm confused.
>
> Thanks.
>
> -Dom
>
> "Mike H" wrote:
>
> > Hi,
> >
> > Like this
> >
> > LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"
> > --
> > Mike
> >
> > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > introduces the fewest assumptions while still sufficiently answering the
> > question.
> >
> >
> > "PVANS" wrote:
> >
> > > Hi All,
> > >
> > > Hope someone can help me with this.
> > >
> > > I am trying to find a method of finding the first blank row on a worksheet
> > > and perform a sum calculation for column B:
> > >
> > > example:
> > > Before
> > > A B
> > > ww ww
> > > x 1
> > > x 2
> > > x 5
> > > x 6
> > >
> > > After
> > > ww ww
> > > A B
> > > x 1
> > > x 2
> > > x 5
> > > x 6
> > > 14
> > >
> > > I have code to find the first blank row:
> > > Dim NextRow As Long
> > > NextRow = Range("B65536").End(xlUp).Row + 1
> > > Cells(NextRow, 2) = "test"
> > >
> > > But of course, I don't want it to say test, but insteade calulate the sum of
> > > all values in the column from B2 down (B1 has heading)
> > >
> > > Thank you, really appreciate any help

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      18th Mar 2010
Actually looking at it my syntax was mixed

I could have been consistent by using

LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Cells(LastRow + 1, "B").Formula = "=Sum(B2:B" & LastRow & ")"

or

LastRow = Cells(Cells.Rows.Count, 2).End(xlUp).Row
Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"

But I mixed to 2 different methods together and i wasn't aware I habitually
did that until now.
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

> > Can you explain what the "B" represents in your first line?

>
> LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
>
> The B represent column B and no the 2 values for 'CELL' don't have to be
> integer
>
> Cells(1, "B").Value = "wwwww"
> is the same as
> Cells(1, 2).Value = "wwwww"
>
> HTH
>
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "Domenick" wrote:
>
> > Mike,
> >
> > Can you explain what the "B" represents in your first line? Doesnt the
> > argument for Cells have to be (<integer>,<integer>)? I'm confused.
> >
> > Thanks.
> >
> > -Dom
> >
> > "Mike H" wrote:
> >
> > > Hi,
> > >
> > > Like this
> > >
> > > LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > > Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"
> > > --
> > > Mike
> > >
> > > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > > introduces the fewest assumptions while still sufficiently answering the
> > > question.
> > >
> > >
> > > "PVANS" wrote:
> > >
> > > > Hi All,
> > > >
> > > > Hope someone can help me with this.
> > > >
> > > > I am trying to find a method of finding the first blank row on a worksheet
> > > > and perform a sum calculation for column B:
> > > >
> > > > example:
> > > > Before
> > > > A B
> > > > ww ww
> > > > x 1
> > > > x 2
> > > > x 5
> > > > x 6
> > > >
> > > > After
> > > > ww ww
> > > > A B
> > > > x 1
> > > > x 2
> > > > x 5
> > > > x 6
> > > > 14
> > > >
> > > > I have code to find the first blank row:
> > > > Dim NextRow As Long
> > > > NextRow = Range("B65536").End(xlUp).Row + 1
> > > > Cells(NextRow, 2) = "test"
> > > >
> > > > But of course, I don't want it to say test, but insteade calulate the sum of
> > > > all values in the column from B2 down (B1 has heading)
> > > >
> > > > Thank you, really appreciate any help

 
Reply With Quote
 
Domenick
Guest
Posts: n/a
 
      18th Mar 2010
Ahhh.. It is crystal clear now! Thanks for the clarification.

-Dom

"Mike H" wrote:

> Actually looking at it my syntax was mixed
>
> I could have been consistent by using
>
> LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> Cells(LastRow + 1, "B").Formula = "=Sum(B2:B" & LastRow & ")"
>
> or
>
> LastRow = Cells(Cells.Rows.Count, 2).End(xlUp).Row
> Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"
>
> But I mixed to 2 different methods together and i wasn't aware I habitually
> did that until now.
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "Mike H" wrote:
>
> > > Can you explain what the "B" represents in your first line?

> >
> > LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> >
> > The B represent column B and no the 2 values for 'CELL' don't have to be
> > integer
> >
> > Cells(1, "B").Value = "wwwww"
> > is the same as
> > Cells(1, 2).Value = "wwwww"
> >
> > HTH
> >
> >
> > --
> > Mike
> >
> > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > introduces the fewest assumptions while still sufficiently answering the
> > question.
> >
> >
> > "Domenick" wrote:
> >
> > > Mike,
> > >
> > > Can you explain what the "B" represents in your first line? Doesnt the
> > > argument for Cells have to be (<integer>,<integer>)? I'm confused.
> > >
> > > Thanks.
> > >
> > > -Dom
> > >
> > > "Mike H" wrote:
> > >
> > > > Hi,
> > > >
> > > > Like this
> > > >
> > > > LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > > > Cells(LastRow + 1, 2).Formula = "=Sum(B2:B" & LastRow & ")"
> > > > --
> > > > Mike
> > > >
> > > > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > > > introduces the fewest assumptions while still sufficiently answering the
> > > > question.
> > > >
> > > >
> > > > "PVANS" wrote:
> > > >
> > > > > Hi All,
> > > > >
> > > > > Hope someone can help me with this.
> > > > >
> > > > > I am trying to find a method of finding the first blank row on a worksheet
> > > > > and perform a sum calculation for column B:
> > > > >
> > > > > example:
> > > > > Before
> > > > > A B
> > > > > ww ww
> > > > > x 1
> > > > > x 2
> > > > > x 5
> > > > > x 6
> > > > >
> > > > > After
> > > > > ww ww
> > > > > A B
> > > > > x 1
> > > > > x 2
> > > > > x 5
> > > > > x 6
> > > > > 14
> > > > >
> > > > > I have code to find the first blank row:
> > > > > Dim NextRow As Long
> > > > > NextRow = Range("B65536").End(xlUp).Row + 1
> > > > > Cells(NextRow, 2) = "test"
> > > > >
> > > > > But of course, I don't want it to say test, but insteade calulate the sum of
> > > > > all values in the column from B2 down (B1 has heading)
> > > > >
> > > > > Thank you, really appreciate any help

 
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
If Cell in Column C is Blank, Make Adjacent Cell in Column B Blank ryguy7272 Microsoft Excel Programming 6 13th Jul 2009 10:05 PM
Multi-column pages. Need to leave 3rd column blank J Wilkes Microsoft Word Document Management 2 26th Aug 2008 05:34 PM
Copying a formula in a blank column as far as data in previous column basildon Microsoft Excel Programming 1 16th Dec 2005 03:32 PM
Sorting blank and non blank column of data Hari Microsoft Excel Misc 1 23rd Jul 2004 12:13 AM
VB- If first cell with formula is blank, all cells in column returns blank. mnhesh Microsoft Excel Misc 2 12th May 2004 05:14 PM


Features
 

Advertising
 

Newsgroups
 


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