count every ten seconds using excel and Visual Basic - excel-2010

I am trying to count every ten seconds in a column in excel using Visual Basic
what code do I have to write in order to repeat this function every ten seconds [enter image description here][1]
this is my cloumn I am trying to write in column (k) which ten seconds are they
for example : the first ten seconds are number 1 so in column k appears number one, the seconde ten seconds are number two.....
[1]: https://i.stack.imgur.com/2XIIt.png

I'm not totally sure what you want to achieve, but it sounds like you want to run a timer with an interval of 10 seconds, and every time it runs, you want to alter the next row or column of a table. If so, something like this should work:
Class MyClass
Private NbElapsed As Integer = 1
Private WithEvents TenSecondTimer As New System.Timers.Timer(10000) With { .AutoReset = True }
Private SC As SynchronizationContext = SynchronizationContext.Current
Private Sub TenSecondTimer_Elapsed(sender As Object, e As EventArgs) Handles RestrictionTimer.Elapsed
SC.Post(AddressOf Elapsed, Nothing)
End Sub
Private Sub Elapsed(args as Object = Nothing)
NbElapsed += 1
' TODO: Alter column with index NbElapsed
End Sub
End Class

Related

Looping a different number of times (determined by value in data) for each line

I have to create a loop, but the size of this loop have to change according the cell value. But I don't know how to reference a specific cell.
Example - my dataset has 2 rows:
Id value
1 10
2 20
For the first row I have to run this loop 10 times, but for the second row I have to run 20 times.
How I can do this?
How about this:
loop # = 1 to 1000. /*use the maximum number or runs necessary.
do if # <= value.
some transformations.
end if.
end loop.
This will run the transformations on all cases every time, but will stop when the number of required runs for each line is reached.

Excel: Count no. of times last value in a row occured

Am sorry am unable to paste the table here as my work laptop security doesn't let me.
I have a row with multiple repetitive values eg columnB to BI containing 2s, 3s, 1s, and 3s again.
The value in last column is 3. I want to count for last how many columns was the value 3 before it changed to something else.
For example: if the row looks like
2 2 3 3 3 1 1 2 2 3 3 2 2 2 2 2 , then the answer I want is 5, because the last value is 2 and it was there for last 5 columns.
I hope it makes sense.
Thank you,
Parul.
You can do it by creating a UDF(User Defined Function) in VBA like this one:
Function CountLast(x As Range, y As Integer)
Dim lColumn, count
lColumn = x.Cells(x.count).Column 'Get last column in range x
count = 0
For i = lColumn To 0 Step -1 'Start with last column and work from right to left
If Cells(1, i).Value <> y Then 'Compare value of each cell with the value provided in y and leave the loop if not found
Exit For
End If
count = count + 1 'Counts how many times the value is found
Next i
CountLast = count 'Returns the counted value
End Function
Then you would use it like this:
=CountLast(B1:BI1,BI1)
For the example data that you provide in your question I used:
=CountLast(A1:P1,P1)
and the resulting answer is 5
What is happening is that the UDF is finding the last cell in the range and then starting there is comparing it to the selected value that you also provide the function and working from right to left (step -1) then it counts as long as they match and in the end returns the counted value.

Selecting an item from a listbox to show more items in another listbox?

Alright, so i have a problem with my programming, i have three checkedlistboxes, one called "lstShows" 2nd is called "lstSeasons" and third is called "lstEpisodes" and i have two comboboxes that have seasons and episodes in them, one combobox is called "cbSeasons" and 2nd is called "cbEpisodes. so what i'm trying to do is, when i press on an item in lstshows, i want to be able to assign to it items from lstSeasons, and when i want to click on an item in seasons i want to be able to assign items to it in lstepisodes
So for example lets say, a tv shows contains 10 seasons, so i add that tv shows and assign 10 seasons for it, then season 1, has 20 episodes, and seasons 2 has 15 episodes, i want to be able to add items to each different show, and season. i have been looking every where but i could not find anything.
Here is the layout https://www.dropbox.com/s/u6xc3sb43ksq8qr/Capture.PNG?dl=0
and i tried to do the code, i done this but it does not work.
Dim item As String = lstSeasons.SelectedItem
lstEpisodes.Items.Add(item)
I really need help with this.
Thank you.
First of all, your data must be stored somewhere.
For example, you can have one worksheet per show, have the seasons in column A and for each season have the episodes in the same row (starting at column B). If you don't want this data to be seen, just hide the sheets.
So if I understood correctly, first you want to select a show, then the seasons of this show appear in the 2nd listbox, and then when you select a season the episodes of this season appear in the 3rd listbox.
First, you need to add all you shows to the 1st listbox. Here, I'll assume that you have 10 shows, that their corresponding worksheets are Worksheets(1) to Worksheets(10), and that the name of the worksheet is the name of the show (but you can do as you wish, for example storing the show's name in a particular cell).
Dim showName as String
For i = 1 To 10
showName = Worksheets(i).Name
lstShows.AddItem showName
Next i
Then, to get the seasons listbox to change when you select a particular show, you can do this :
Private Sub lstShows_Change()
Call Me.lstSeasons.Clear
showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row
Dim i As Integer
For i = 1 To rowCount
Me.lstSeasons.AddItem sh.Cells(i,1).Value
Next i
End Sub
And to get the episodes listbox to change when you select a particular season, you can do this :
Private Sub lstSeasons_Change()
Call Me.lstEpisodes.Clear
showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row
Dim colCount As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To rowCount
If Me.lstSeasons.Value = sh.Cells(i,1).Value Then
colCount = sh.Cells(i, sh.Columns.Count).End(xlToLeft).Column
For j = 2 To colCount
Me.lstEpisodes.AddItem sh.Cells(i,j).Value
Next j
Next i
End Sub
Hope this will help !
First thing I believe you need to do is to put a multi dimensional array to store your information.
More details about jagged arrays: https://msdn.microsoft.com/en-us/library/hkhhsz9t(v=vs.90).aspx
so you can use it this way for example:
Dim shows(50)(50) As string
This will give you 50 "shows" with 50 episodes each. now you can change those using the program as needed.
Now into the next part which is inserting those in. You can modify them by assigning a value by
shows(1)(12) = "ep12nameofshow1"
Where you can assign the string as a variable if you want to be able to manually change the name during runtime
Now you want to add the items to your listbox! So lets go over that with a great little for-loop
For Each episode As String In shows(1) 'show number here
lstEpisodes.Items.Add(episode)
Next
please note that I didn't test this since I don't have access to most of your code so please inform me if there are any problems you are facing.
Update This code should be working:
1- Add this at top of your page (below class declaration)
Dim showEpisodes(99)(99)() As String
think of it as showEpisodes(Show#,Season#,Ep#)
2- Add values to your array. How you do that is up to you (use a file, database or just predetermined values. You can even put them in run time. But that's another thing for another question!)
3- Add this part to your season's code
For Each element As String In showEpisodes(lstShows.SelectedIndex)(lstSeasons.SelectedIndex)
lstEpisodes.Items.Add(element)
Next

Rotate Sheets in Google Spreadsheet every 10 sec

I have 5 sheets in my Google Spreadsheet document and i am trying to see if it is possible have a plugin or function to rotate each sheets every 10 sec?
Please let me know.
thanks
Found this thread on how to set the spreadsheet to switch between the different sheets every N seconds.
Example:
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Sub Switch()
Dim ws As Worksheet
Do
For Each ws In ThisWorkbook.Worksheets
ws.Activate
Application.Wait Now() + TimeValue("00:00:05")
If GetAsyncKeyState(vbKeyShift) Then Exit Sub
DoEvents
Next ws
Loop
End Sub
This will loop through all worksheets in the current workbook every five seconds, then when it's done it loops round to do again.

Call center Calculating monthly and annual percentage

I'm trying to put together management information for a call center.
I've got the following info on every call that gets logged:
[CreatedOn] = Date & time of creation
[Case_status_name] = Reason for closing the call (Answered by 1st line, transferred to 2nd, call back request etc.)
Now what I'm looking to make is a graph which will show in one line the % of calls that were answered by the 1st line and the annual average% of calls closed by the first line during the last 12 months.
I can get the months from [CreatedOn] with the extract function, the same goes for the year.
I can group the [Case_status_name] in 1st line answered and everything else with a simple if statement.
But I'm having trouble getting the percentages right for both the month and the year together.
I can get sensible data if I only calculate the yearly average or if I calcluate the monthly average. But when I try to do them together, I wind up getting all kinds of crazy values.
What is a proper way to get the monthly and annual percentage in the same table?
Create Query
Add Column [Month] with expression
_first_of_month([CreatedOn])
Add Query Item [Total] with expression
1
Add Query Item [Answered by 1st line] with expression
case when [Case_status_name] = 'Answered by 1st line' then 1 else 0 end
Add Query Item [closed by the first line] with expression
case when [Case_status_name] = 'closed by the first line' then 1 else 0 end
Filter this Query
[CreatedOn] between _first_of_month(_add_months(current_date;-12))
and _last_of_month(_add_months(current_date;-1))
Add Query Item [% of calls answered by the 1st line] with expression
[Answered by 1st line] / [Total]
Add Query Item [12-month average] with expression
sum([closed by the first line] for report) / sum([Total] for report)
Build Graph based on this Query

Resources