Telefonstolpe
Board Regular
- Joined
- Sep 25, 2014
- Messages
- 55
Hi,
If I manually change interior color on a cell in the worsheet and afterwards run a macro excel crashes.
It happens on most of the macros i'm using.
Anybody who has any idea about what the issue can be?
I'll include a very simple macro here as an example:
/Chris
If I manually change interior color on a cell in the worsheet and afterwards run a macro excel crashes.
It happens on most of the macros i'm using.
Anybody who has any idea about what the issue can be?
I'll include a very simple macro here as an example:
Code:
Sub PRI_AntalJustera_()Dim rad As Long
Dim kGrupp As Long
Dim kMärke As Long
Dim kTyp As Long
Dim kAntal As Long
Dim RngGrupp As Range
Dim Ruta As Range
'Förbered XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'On Error GoTo Av****a
Application.ScreenUpdating = False
Application.EnableEvents = False
ThisWorkbook.Activate
Blad1.Select
'Ta bort protection när makro körs
'---------------------------------------------------------------------------
'Set variables XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
rad = Selection.Row
kGrupp = Range("PRIk_Grupp").Column
kMärke = Range("PRIk_Märke").Column
kTyp = Range("PRIk_Typ").Column
kAntal = Range("PRIk_Antal").Column
Set RngGrupp = Range("PRIk_Grupp")
'---------------------------------------------------------------------------
'Villkor XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
If Selection.Rows.Count <> 1 Then GoTo Fel1
If Intersect(Selection, Range("Tabell1")) Is Nothing Then GoTo Fel1
If Cells(rad, kTyp) = "Rubrik" Then GoTo Av****a
If Cells(rad, kTyp) = "Handbok" Then GoTo Fel2
'---------------------------------------------------------------------------
'JUSTERA ANTAL XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'Lägg till eventuella handböcker *********
If Cells(rad, kAntal) < 1 And PubAntal < 1 Then GoTo Av****a
If Cells(rad, kTyp) = "Printer" Then
If Cells(rad, kMärke) = "Ricoh" Then
For Each Ruta In RngGrupp
If Ruta.Value = Cells(rad, kGrupp) Then
If Cells(Ruta.Row, kTyp) = "Handbok" Then
Cells(Ruta.Row, kAntal) = Cells(Ruta.Row, kAntal) + PubAntal
If Cells(Ruta.Row, kAntal) < 1 Then Cells(Ruta.Row, kAntal) = ""
GoTo Nästa
End If
End If
Next Ruta
End If
End If
Nästa:
'*****************************************
'Justera vald cell ***********************
Cells(rad, kAntal) = Cells(rad, kAntal) + PubAntal
If Cells(rad, kAntal) < 1 Then Cells(rad, kAntal) = ""
'*****************************************
'---------------------------------------------------------------------------
'Fel XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
GoTo Av****a:
Fel1:
'Application.ScreenUpdating = True
MsgBox "Du måste markera max en rad i tabellen"
GoTo Av****a
Fel2:
'Application.ScreenUpdating = True
MsgBox "Du kan inte välja antal handböcker. Antalet handböcker läggs automatiskt till när du lägger till skrivare"
GoTo Av****a
'---------------------------------------------------------------------------
'Av****a XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Av****a:
Application.ScreenUpdating = True
Application.EnableEvents = True
'---------------------------------------------------------------------------
End Sub
/Chris