Dansk Regneark Forum
  Hjælp Hjælp  Søg i forum   Opret ny bruger Opret ny bruger  Log ind Log ind


Emne lukketMsgBox hvis

 Besvar Besvar
Forfatter
Mikkel Se dropdown
Bronze bruger
Bronze bruger


Medlem: 24.Maj.2013
Status: Offline
Point: 36
Direkte link til dette indlæg Emne: MsgBox hvis
    Sendt: 15.Dec.2015 kl. 16:13
Hej Forum,

Jeg kan ikke rigtigt få denne stump til at virke.

Meningen er den skal løbe gennem kolonne S og checke om der er tal over 8!
Er der det skal den komme op med en boks, med en besked.

koden ser således ud:

Private Sub Worksheet_Calculate()
  If Intersect(Target, Range("S:S")) Is Nothing Then Exit Sub
    If Target.Value = ">8" Then
        MsgBox "You entered to many hrs. for travelling", vbExclamation
    End If
End Sub

            

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F1:F100")) Is Nothing Then Exit Sub
If Target.Value = "Transport Hotel/Site - Site/Hotel" Then MsgBox "You have chosen Transport Hotel/Site - Site/Hotel, When working Offshore you are only entitled, to book 12,00 hours a day in total", vbExclamation
If Target.Value = "Travelling Onshore (home/site - site/home - site/site)" Then MsgBox "You have chosen Travelling Onshore (home/site - site/home - site/site), When working Offshore you are only entitled, to book 8,00 hours per travel in total", vbExclamation
If Target.Value = "Work time Onshore" Then MsgBox "You have chosen Work time Onshore, Please consider, to give detailed description and with an NCR number if applicable", vbExclamation
If Target.Value = "Indirect time on site Offshore" Then MsgBox "You have chosen Indirect time on site Offshore, When Indirect time, check your garanteed hours for this day, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Indirect time on site Onshore" Then MsgBox "You have chosen Indirect time on site Offshore, When Indirect time, check your garanteed hours for this day, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Indirect time off site Onshore (abroad)" Then MsgBox "You have chosen Indirect time on site Onshore (abroad), When Indirect time, check your garanteed hours for this day, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Indirect time off site Onshore (home)" Then MsgBox "You have chosen Indirect time on site Onshore (home), When Indirect time, check your garanteed hours while at Home, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Transport Offshore" Then MsgBox "You have chosen Transport Offshore, Offshore Transport hours, are not to exceed 12 hours per day", vbExclamation


End Sub


Til top



Til top
jespergn Se dropdown
Bronze bruger
Bronze bruger
Avatar

Medlem: 23.Sep.2014
Status: Offline
Point: 90
Direkte link til dette indlæg Sendt: 16.Dec.2015 kl. 12:51

Public Sub FindHours()

Dim sht As Worksheet
Dim LastRow As Long
Dim i As Long

Set sht = ThisWorkbook.Worksheets("Ark1")

    LastRow = sht.Cells(sht.Rows.Count, "S").End(xlUp).Row
   
    For i = 1 To LastRow
        If Cells(i, 19) > 8 Then
        MsgBox "You entered to many hrs. for travelling in row " & i
    End If

Next i
End Sub

Skift Ark1 ud med arket på dit navn.
Til top
Mikkel Se dropdown
Bronze bruger
Bronze bruger


Medlem: 24.Maj.2013
Status: Offline
Point: 36
Direkte link til dette indlæg Sendt: 16.Dec.2015 kl. 13:19
Hej,

Jespergn´s forsøg virker ikke helt efter hensigten, desværre kommer den op med MsgBox i samtlige celler, uden at der er nogen værdi.

Mikkel
Til top
excelent Se dropdown
Guld bruger
Guld bruger
Avatar

Medlem: 12.Apr.2011
Land: DK
Status: Offline
Point: 2171
Direkte link til dette indlæg Sendt: 16.Dec.2015 kl. 20:19
Udskift dine 2 koder med denne :
 
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F1:F100")) Is Nothing Then
If Target.Value = "Transport Hotel/Site - Site/Hotel" Then MsgBox "You have chosen Transport Hotel/Site - Site/Hotel, When working Offshore you are only entitled, to book 12,00 hours a day in total", vbExclamation
If Target.Value = "Travelling Onshore (home/site - site/home - site/site)" Then MsgBox "You have chosen Travelling Onshore (home/site - site/home - site/site), When working Offshore you are only entitled, to book 8,00 hours per travel in total", vbExclamation
If Target.Value = "Work time Onshore" Then MsgBox "You have chosen Work time Onshore, Please consider, to give detailed description and with an NCR number if applicable", vbExclamation
If Target.Value = "Indirect time on site Offshore" Then MsgBox "You have chosen Indirect time on site Offshore, When Indirect time, check your garanteed hours for this day, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Indirect time on site Onshore" Then MsgBox "You have chosen Indirect time on site Offshore, When Indirect time, check your garanteed hours for this day, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Indirect time off site Onshore (abroad)" Then MsgBox "You have chosen Indirect time on site Onshore (abroad), When Indirect time, check your garanteed hours for this day, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Indirect time off site Onshore (home)" Then MsgBox "You have chosen Indirect time on site Onshore (home), When Indirect time, check your garanteed hours while at Home, your total ammount of hours are not to exceed the guranteed hours", vbExclamation
If Target.Value = "Transport Offshore" Then MsgBox "You have chosen Transport Offshore, Offshore Transport hours, are not to exceed 12 hours per day", vbExclamation
End If
If Intersect(Target, Range("S1:S1000")) Is Nothing Then Exit Sub
  If Target.Value > 8 Then
    MsgBox "You entered to many hrs. for travelling", vbExclamation
      ActiveCell.Offset(-1, 0).Select
    Target = ""
  End If
End Sub
 
Jeg anvender Excel 2016 DK. Hvad anvender DU ? HUSK TILBAGEMELDING !!!
Til top
Mikkel Se dropdown
Bronze bruger
Bronze bruger


Medlem: 24.Maj.2013
Status: Offline
Point: 36
Direkte link til dette indlæg Sendt: 17.Dec.2015 kl. 16:10
Hej,

Det virker desværre ikke som det skal.

Er der en venlig sjæl, som kan se hvad der er galt, med koden herunder, der er lavet lidt om på det så det er nemmere at rette i "beskederne" til brugeren, men det ser ikke ud til at virke desværre.

Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim feedback As String 
    Const msg As String = "You have chosen - " 
    Const msg_Guaranteed As String = "your total ammount of hours are not to exceed the guranteed hour" 
    Const msg1 As String = "When working Offshore you are only entitled, to book 12,00 hours a day in total" 
    Const msg2 As String = "When working Offshore you are only entitled, to book 8,00 hours per travel in total" 
    Const msg3 As String = "Please consider, to give detailed description and with an NCR number if applicable" 
    Const msg4 As String = "When Indirect time, check your garanteed hours for this day, " & msg_Guaranteed 
    Const msg5 As String = "When Indirect time, check your garanteed hours for this day, " & msg_Guaranteed 
    Const msg6 As String = "When Indirect time, check your garanteed hours for this day, " & msg_Guaranteed 
    Const msg7 As String = "When Indirect time, check your garanteed hours while at Home, " & msg_Guaranteed 
    Const msg8 As String = "Offshore Transport hours, are not to exceed 12,00 hours per day" 
     
    On Error GoTo wsc_exit 
     
    Application.EnableEvents = False 
     
    If Intersect(Target, Me.Range("F6:F123,M6:M123,N6:N123")) Is Nothing Then Exit Sub 
     
    If Me.Cells(Target.Row, "S").Value > 8 Then 
         
        Select Case Me.Cells(Target.Row, "F").Value 
             
        Case "Transport Hotel/Site - Site/Hotel":                       feedback = msg1 
        Case "Travelling Onshore (home/site - site/home - site/site)":  feedback = msg2 
        Case "Work time Onshore":                                       feedback = msg3 
        Case "Indirect time on site Offshore":                          feedback = msg4 
        Case "Indirect time on site Onshore":                           feedback = msg5 
        Case "Indirect time off site Onshore (abroad)":                 feedback = msg6 
        Case "Indirect time off site Onshore (home)":                   feedback = msg7 
        Case "Transport Offshore":                                      feedback = msg8 
        End Select 
         
        If feedback <> "" Then 
             
            MsgBox msg & vbNewLine & Me.Cells(Target.Row, "F").Value & vbNewLine & vbNewLine & feedback, vbExclamation 
            Me.Cells(Target.Row, "M").Resize(, 2).Value = "" 
        End If 
    End If 
     
wsc_exit: 
    Application.EnableEvents = True 
End Sub 

Til top
 Besvar Besvar

Skift forum Forum tilladelser Se dropdown

© 2010 - 2026 Dansk Regneark Forum – en del af Excel-regneark.dk