Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default New to VBA - help required please.

Hi folks,

I have been given assistance with some VBA code to calculate a winning
or unbeaten streak in my spreadsheet - it counts the W (Win) and D
(Draw) occurences in a column of the sheet.
Sub WinLossStreak()
Dim wks As Worksheet
Dim rng As Range
Dim rngBeginCheckingHere As Range
Dim intWinStreak As Integer
Dim intBestStreak As Integer

Set wks = ThisWorkbook.Worksheets("Matches")
Set rngBeginCheckingHere = wks.Range("E2")

intWinStreak = 0
For Each rng In wks.Range(rngBeginCheckingHere, _
Cells(Rows.Count, rngBeginCheckingHere.Column).End(xlUp))
If rng.Value = "W" Or rng.Value = "D" Then
intWinStreak = intWinStreak + 1
' Check the current win streak vs.
' the best win streak
If intBestStreak < intWinStreak Then
intBestStreak = intWinStreak
End If
Else
' Current record is a Loss, reset
' the win streak.
intWinStreak = 0
End If
Next rng
MsgBox intBestStreak
End Sub

I have been able to input this OK, and found that using F5 whilst in
the VBA editor, will go to my spreadsheet, and give me a pop-up box
with the answer.

However, I would like this to be automatically updated on my sheet, so
that when I put in new results as a season progresses, this is part of
my stats.

So far, I am using functions such as COUNTIF in my Stats panel to show
number of Wins, Draws and losses etc. but would like to include a Best
Winning streak stat too.

Thus, my question is this, how do I get the result of the above code
to be returned automatically to a cell.

I apologise if this is very rudimentary, but I can't seem to find what
I'm looking for

Thanks
Neil
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default New to VBA - help required please.

Neil,

Instead of
MsgBox intBestStreak

use
Worksheets("Sheet1").Range("A1").Value = intBestStreak

change the sheetname and cell to suit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Neil Grantham" wrote in message
om...
Hi folks,

I have been given assistance with some VBA code to calculate a winning
or unbeaten streak in my spreadsheet - it counts the W (Win) and D
(Draw) occurences in a column of the sheet.
Sub WinLossStreak()
Dim wks As Worksheet
Dim rng As Range
Dim rngBeginCheckingHere As Range
Dim intWinStreak As Integer
Dim intBestStreak As Integer

Set wks = ThisWorkbook.Worksheets("Matches")
Set rngBeginCheckingHere = wks.Range("E2")

intWinStreak = 0
For Each rng In wks.Range(rngBeginCheckingHere, _
Cells(Rows.Count, rngBeginCheckingHere.Column).End(xlUp))
If rng.Value = "W" Or rng.Value = "D" Then
intWinStreak = intWinStreak + 1
' Check the current win streak vs.
' the best win streak
If intBestStreak < intWinStreak Then
intBestStreak = intWinStreak
End If
Else
' Current record is a Loss, reset
' the win streak.
intWinStreak = 0
End If
Next rng
MsgBox intBestStreak
End Sub

I have been able to input this OK, and found that using F5 whilst in
the VBA editor, will go to my spreadsheet, and give me a pop-up box
with the answer.

However, I would like this to be automatically updated on my sheet, so
that when I put in new results as a season progresses, this is part of
my stats.

So far, I am using functions such as COUNTIF in my Stats panel to show
number of Wins, Draws and losses etc. but would like to include a Best
Winning streak stat too.

Thus, my question is this, how do I get the result of the above code
to be returned automatically to a cell.

I apologise if this is very rudimentary, but I can't seem to find what
I'm looking for

Thanks
Neil



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default New to VBA - help required please.

Thanks Bob

I've tried that, and it seemed to work if I updated from the VB editor
(F5), but if I update the sheet results, the cell this applies to
doesn't!
Did I do something wrong?

Neil

"Bob Phillips" wrote in message ...
Neil,

Instead of
MsgBox intBestStreak

use
Worksheets("Sheet1").Range("A1").Value = intBestStreak

change the sheetname and cell to suit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default New to VBA - help required please.

Neil,

What is triggering this macro from the cell? In other words, what are you
doing, and what do you expect that doesn't happen?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Neil Grantham" wrote in message
om...
Thanks Bob

I've tried that, and it seemed to work if I updated from the VB editor
(F5), but if I update the sheet results, the cell this applies to
doesn't!
Did I do something wrong?

Neil

"Bob Phillips" wrote in message

...
Neil,

Instead of
MsgBox intBestStreak

use
Worksheets("Sheet1").Range("A1").Value = intBestStreak

change the sheetname and cell to suit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)



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 REQUIRED Ashwini Excel Discussion (Misc queries) 0 September 25th 08 10:45 AM
Help required Hassan Excel Worksheet Functions 2 July 29th 08 05:38 AM
Help Required.... kiran Excel Discussion (Misc queries) 2 November 4th 06 11:48 AM
Help required Sanjeev Excel Discussion (Misc queries) 1 August 25th 05 07:59 AM
Help required...... Duncan Excel Discussion (Misc queries) 2 February 17th 05 10:26 PM


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

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"