I've got the following bit of code which runs ok, but bogs down the computer. There must be something up with it, but being a newb to vba, I'm having trouble pinning it down. Code is:
Private Sub Worksheet_Calculate()
Dim ws As Worksheet
Dim cel As Range
Dim myRow As Long
Set ws = ThisWorkbook.Sheets("Cymatic")
For Each cel In Range("BV8:BV37,CE8:CE37")
myRow = cel.Row
If Range("E4").Value = "False" Then
If IsEmpty(Range("BA" & myRow)) Then Range("BA" & myRow).Value = Range("BV" & myRow).Value
If IsEmpty(Range("BB" & myRow)) Then Range("BB" & myRow).Value = Range("J" & myRow).Value
If IsEmpty(Range("BC" & myRow)) Then Range("BC" & myRow).Value = Range("BP" & myRow).Value
End If
If Range("E4").Value = "True" Then
If IsEmpty(Range("BA" & myRow)) Then Range("BA" & myRow).Value = Range("CE" & myRow).Value
If IsEmpty(Range("BB" & myRow)) Then Range("BB" & myRow).Value = Range("BR" & myRow).Value
If IsEmpty(Range("BC" & myRow)) Then Range("BC" & myRow).Value = Range("BQ" & myRow).Value
End If
Next cel
If Range("BK1").Value = "Clear" Then
Range("BA8:BI37").ClearContents
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim cel As Range
Dim myRow As Long
Set ws = ThisWorkbook.Sheets("Cymatic")
If Not Intersect(Target, Range("BD8:BD37")) Is Nothing Then
For Each cel In Target
myRow = cel.Row
If ws.Range("BD" & myRow).Value = "PLACED" Then
ws.Range("BX" & myRow).Value = ws.Range("BE" & myRow).Value
ws.Range("BW" & myRow).Value = ws.Range("BF" & myRow).Value
End If
Next cel
End If
End Sub
What I'm trying to do:
1) The BV columns basically have a formula in them that gives the "Lay" command. I'm using the worksheet calculate function to detect this as I believe worksheet_change cannot detect changes via formula (correct me if wrong).
2) Once the lay command is given, Lay, odds and stake get copied over to the active parts of the spreadsheet to trigger a bet.
3) Worksheet change event picks up the "Placed" command to copy the odds and stake values placed to another part of the sheet
4) Bit of code to clear the status cells when race goes in-play
5) Worksheet Calculate to do similar with back commands.
All works fine, but slowly. Even unconnected and changing a single cell with have it hanging for a few seconds. Is it looping over and over? (no stack errors). Any thoughts?
Thanks