Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I work on data starting to a cell a cell with a required va

I have a workbook full of data. I want to sum the data to the left of cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA solution.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How do I work on data starting to a cell a cell with a required va

Try this small macro:

Sub sum_to_a_zero()
Dim v
Dim i As Long
i = InputBox("enter row number: ")
For j = 1 To 256
v = v + Cells(i, j).Value
If Cells(i, j).Value = 0 Then
Exit For
End If
Next
MsgBox (v)
End Sub
--
Gary's Student


"Tom London" wrote:

I have a workbook full of data. I want to sum the data to the left of cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA solution.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How do I work on data starting to a cell a cell with a required va

I am reading this slightly differently to Gary

Sub SumCells()
Const thisRow As Long = 10 '<=== change to suit
Dim iLastCol As Long
Dim nSum As Double
Dim i As Long

iLastCol = Cells(thisRow, Columns.Count).End(xlToLeft).Column
For i = 2 To iLastCol
If Cells(thisRow, i).Value = 0 And _
Cells(thisRow, i).Value < "" Then
nSum = nSum + Cells(thisRow, i - 1).Value
End If
Next i

MsgBox nSum
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Tom London" <Tom wrote in message
...
I have a workbook full of data. I want to sum the data to the left of

cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA

solution.

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do I work on data starting to a cell a cell with a require

Gary

Thanks that works. I'm going to play around with some of the keywords you
used and figure out how.

I want to sum all rows and display the reslt in the first column. Ant
pointers? I suspect this is fairly easy.

Tom

"Gary''s Student" wrote:

Try this small macro:

Sub sum_to_a_zero()
Dim v
Dim i As Long
i = InputBox("enter row number: ")
For j = 1 To 256
v = v + Cells(i, j).Value
If Cells(i, j).Value = 0 Then
Exit For
End If
Next
MsgBox (v)
End Sub
--
Gary's Student


"Tom London" wrote:

I have a workbook full of data. I want to sum the data to the left of cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA solution.

Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do I work on data starting to a cell a cell with a require

Bob

Thanks

The programme appears to be adding the number of occurences in a row of the
0 digit and deducting 1 when I run it. I need to sum all the data to the left
of the 1st (leftmost) 0 in a row and enter that data into column 1.

Thanks again.

Tom

"Bob Phillips" wrote:

I am reading this slightly differently to Gary

Sub SumCells()
Const thisRow As Long = 10 '<=== change to suit
Dim iLastCol As Long
Dim nSum As Double
Dim i As Long

iLastCol = Cells(thisRow, Columns.Count).End(xlToLeft).Column
For i = 2 To iLastCol
If Cells(thisRow, i).Value = 0 And _
Cells(thisRow, i).Value < "" Then
nSum = nSum + Cells(thisRow, i - 1).Value
End If
Next i

MsgBox nSum
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Tom London" <Tom wrote in message
...
I have a workbook full of data. I want to sum the data to the left of

cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA

solution.

Thanks






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How do I work on data starting to a cell a cell with a require


Sub sum_to_a_zero()
Dim iLastRow As Long
Dim iLastcol As Long
Dim nSum As Double
Dim i As Long, j As Long

iLastRow = ActiveSheet.UsedRange.Rows.Count

For i = 1 To iLastRow
nSum = 0
iLastcol = Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To iLastcol
nSum = nSum + Cells(i, j).Value
If Cells(i, j).Value = 0 Then
Exit For
End If
Next j
Cells(i, "A").Value = nSum
Next i
End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Tom London" wrote in message
...
Gary

Thanks that works. I'm going to play around with some of the keywords you
used and figure out how.

I want to sum all rows and display the reslt in the first column. Ant
pointers? I suspect this is fairly easy.

Tom

"Gary''s Student" wrote:

Try this small macro:

Sub sum_to_a_zero()
Dim v
Dim i As Long
i = InputBox("enter row number: ")
For j = 1 To 256
v = v + Cells(i, j).Value
If Cells(i, j).Value = 0 Then
Exit For
End If
Next
MsgBox (v)
End Sub
--
Gary's Student


"Tom London" wrote:

I have a workbook full of data. I want to sum the data to the left of

cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA

solution.

Thanks



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do I work on data starting to a cell a cell with a require

Bob

That works beautifully. Thank you.

Tom

"Bob Phillips" wrote:


Sub sum_to_a_zero()
Dim iLastRow As Long
Dim iLastcol As Long
Dim nSum As Double
Dim i As Long, j As Long

iLastRow = ActiveSheet.UsedRange.Rows.Count

For i = 1 To iLastRow
nSum = 0
iLastcol = Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To iLastcol
nSum = nSum + Cells(i, j).Value
If Cells(i, j).Value = 0 Then
Exit For
End If
Next j
Cells(i, "A").Value = nSum
Next i
End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Tom London" wrote in message
...
Gary

Thanks that works. I'm going to play around with some of the keywords you
used and figure out how.

I want to sum all rows and display the reslt in the first column. Ant
pointers? I suspect this is fairly easy.

Tom

"Gary''s Student" wrote:

Try this small macro:

Sub sum_to_a_zero()
Dim v
Dim i As Long
i = InputBox("enter row number: ")
For j = 1 To 256
v = v + Cells(i, j).Value
If Cells(i, j).Value = 0 Then
Exit For
End If
Next
MsgBox (v)
End Sub
--
Gary's Student


"Tom London" wrote:

I have a workbook full of data. I want to sum the data to the left of

cells
containing 0. The 0 occurs randomly. Any solutions appreciated but am
learning VBA at the moment and would particularly appreciate a VBA

solution.

Thanks




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 vlookup of one cell by starting 2 digits of another cell? Uday Excel Worksheet Functions 1 February 10th 10 04:58 AM
Macro for cell selection starting with Last Cell Valerie Excel Worksheet Functions 4 December 9th 05 08:25 PM
I want to sort Data A-Z starting at Cell A1 to C34 Susie Q Excel Discussion (Misc queries) 1 September 30th 05 06:37 PM
Cell data required upon close pjhageman[_11_] Excel Programming 2 January 12th 04 02:45 PM
Change Cell Data of a Required Column jonathan Excel Programming 0 January 8th 04 09:28 PM


All times are GMT +1. The time now is 04:13 AM.

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

About Us

"It's about Microsoft Excel"