Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Run code from one worksheet to populate another.

I have 2 worksheets in the same workbook called "DATA" and "Scores".

Structure of sheet "Scores" is as follows

A B C
1 Player Caps goals
2 Beckham 65
3 Shearer 67
4 Beattie 2




I need to populate column C with number of goals scored by each player
(Column A) from worksheet "DATA". The code below runs fine when I select the
player (Range A) to become the ActiveCell and then run the code and only if
the code and the three column are in the same worksheet, which is "sheet
"DATA".


I need to add a loop to the code to run it from sheet "scores". Of course
the line
mScorer = ActiveCell
needs to be changed to reflect going through all the players





Public Sub SumGoals()

Dim mScorer As String
Dim mTotal As Integer
Dim mGoals As Integer
Dim myCell As Range

mTotal = 0
mScorer = ActiveCell

With Worksheets("Data").Range("AD3:AL500")

For Each c In Range("AD2:AL500")

If c.Value = mScorer Then
firstAddress = c.Address
mGoals = c.Offset(0, 1).Value
mTotal = mTotal + mGoals
End If
Next c
End With

If mTotal 0 Then
ActiveCell.Offset(0, 3).Value = mTotal
End If


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Run code from one worksheet to populate another.

Public Sub SumGoals()
Dim cellRow As String, firstAddress As String
Dim mScorer As String
Dim mTotal As Integer
Dim mGoals As Integer
Dim myCell As Range
Dim c As Object

mTotal = 0
cellRow = ActiveCell.Row
mScorer = ActiveSheet.Range("A" & cellRow)

With Worksheets("Data").Range("AD3:AL500")

For Each c In Range("AD2:AL500")

If c.Value = mScorer Then
firstAddress = c.Address
mGoals = c.Offset(0, 1).Value
mTotal = mTotal + mGoals
End If
Next c
End With

If mTotal 0 Then
ActiveSheet.Range("A" & cellRow).Offset(0, 3).Value =
mTotal
End If


End Sub


-----Original Message-----
I have 2 worksheets in the same workbook called "DATA"

and "Scores".

Structure of sheet "Scores" is as follows

A B C
1 Player Caps goals
2 Beckham 65
3 Shearer 67
4 Beattie 2




I need to populate column C with number of goals scored

by each player
(Column A) from worksheet "DATA". The code below runs

fine when I select the
player (Range A) to become the ActiveCell and then run

the code and only if
the code and the three column are in the same worksheet,

which is "sheet
"DATA".


I need to add a loop to the code to run it from

sheet "scores". Of course
the line
mScorer = ActiveCell
needs to be changed to reflect going through all the

players





Public Sub SumGoals()

Dim mScorer As String
Dim mTotal As Integer
Dim mGoals As Integer
Dim myCell As Range

mTotal = 0
mScorer = ActiveCell

With Worksheets("Data").Range("AD3:AL500")

For Each c In Range("AD2:AL500")

If c.Value = mScorer Then
firstAddress = c.Address
mGoals = c.Offset(0, 1).Value
mTotal = mTotal + mGoals
End If
Next c
End With

If mTotal 0 Then
ActiveCell.Offset(0, 3).Value = mTotal
End If


End Sub


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Run code from one worksheet to populate another.

Thanks losmac , but this code does not loop through worksheet "Scores" and
somehow does not run the code to calculate the number of goal from worksheet
"Data"


"losmac" wrote in message
...
Public Sub SumGoals()
Dim cellRow As String, firstAddress As String
Dim mScorer As String
Dim mTotal As Integer
Dim mGoals As Integer
Dim myCell As Range
Dim c As Object

mTotal = 0
cellRow = ActiveCell.Row
mScorer = ActiveSheet.Range("A" & cellRow)

With Worksheets("Data").Range("AD3:AL500")

For Each c In Range("AD2:AL500")

If c.Value = mScorer Then
firstAddress = c.Address
mGoals = c.Offset(0, 1).Value
mTotal = mTotal + mGoals
End If
Next c
End With

If mTotal 0 Then
ActiveSheet.Range("A" & cellRow).Offset(0, 3).Value =
mTotal
End If


End Sub


-----Original Message-----
I have 2 worksheets in the same workbook called "DATA"

and "Scores".

Structure of sheet "Scores" is as follows

A B C
1 Player Caps goals
2 Beckham 65
3 Shearer 67
4 Beattie 2




I need to populate column C with number of goals scored

by each player
(Column A) from worksheet "DATA". The code below runs

fine when I select the
player (Range A) to become the ActiveCell and then run

the code and only if
the code and the three column are in the same worksheet,

which is "sheet
"DATA".


I need to add a loop to the code to run it from

sheet "scores". Of course
the line
mScorer = ActiveCell
needs to be changed to reflect going through all the

players





Public Sub SumGoals()

Dim mScorer As String
Dim mTotal As Integer
Dim mGoals As Integer
Dim myCell As Range

mTotal = 0
mScorer = ActiveCell

With Worksheets("Data").Range("AD3:AL500")

For Each c In Range("AD2:AL500")

If c.Value = mScorer Then
firstAddress = c.Address
mGoals = c.Offset(0, 1).Value
mTotal = mTotal + mGoals
End If
Next c
End With

If mTotal 0 Then
ActiveCell.Offset(0, 3).Value = mTotal
End If


End Sub


.



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
Help on VBA Code to populate multiple sheets [email protected] Excel Discussion (Misc queries) 1 January 15th 08 04:40 AM
populate cell on worksheet 2 if text is red on worksheet 1 SCrowley Excel Worksheet Functions 14 May 15th 07 09:28 PM
Use a code to populate a cell with a specific value braveT Excel Worksheet Functions 5 April 13th 07 10:02 PM
VBA code to populate 1000's of cells? [email protected] Excel Discussion (Misc queries) 14 March 31st 06 06:12 AM
HOW ?Excel chart auto insert /populate a code based on date MikeR-Oz New Users to Excel 6 December 22nd 05 12:16 PM


All times are GMT +1. The time now is 11:20 PM.

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"