MrThor

New Member
Joined
Aug 13, 2018
Messages
36
Hi,

I Have three comboboxes called "År", "Månad" And "Dag". I want "Dag" depend on the values from the other two comboboxes. The first code works for "Dag" depending on "År", then I added an And statement to include "Månad" but after that it doesnt work. Anyone knows what the error is?

Code:
Private Sub År_Change()


Dim j As Integer


Application.EnableEvents = False
Dag.Clear
Application.EnableEvents = True


For j = 0 To 100 Step 4


If År = 2016 + j Then
        Call Månad_skottår
End If




Next j




End Sub

Code:
Private Sub År_Change()


Dim j As Integer


Application.EnableEvents = False
Dag.Clear
Application.EnableEvents = True


For j = 0 To 100 Step 4


If År = 2016 + j Then And Me.År.Value = "Februari"
        Call Månad_skottår
End If




Next j


End Sub

Thanks for your help
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Then is in the wrong place
Code:
If År = 2016 + j [COLOR=#b22222]Then[/COLOR] And Me.År.Value = "Februari"
        Call Månad_skottår
End If

TRY
Code:
If År = 2016 + j And Me.År.Value = "Februari" [COLOR=#b22222]Then[/COLOR]
        Call Månad_skottår
End If
 
Last edited:
Upvote 0
Hi, actually, I just forgot to wrote in in the thread, but it odes not work in that way anyway...
 
Upvote 0
I want "Dag" to depend on the values from År & Månad


Code:
If [COLOR=#ff0000]År[/COLOR] = 2016 + j And Me.[COLOR=#ff0000]År[/COLOR].Value = "Februari" Then


Where is Månad in the code?
 
Last edited:
Upvote 0
Hi, again an error from me, but it still doesnt work.

Code:
Private Sub År_Change()


Dim j As Integer


Application.EnableEvents = False
Dag.Clear
Application.EnableEvents = True


For j = 0 To 100 Step 4


If År = 2016 + j Then And Me.Månad.Value = "Februari" Then
        Call Månad_skottår
End If


Next j


End Sub
 
Upvote 0
Are the 3 comboboxes on a userform?
 
Upvote 0
:eek: Be very careful with VBA. VBA is cruel and very picky! It punishes every mistake -check everything. Be PRECISE

3 errors in a short thread :confused:

1
Hi, actually, I just forgot to wrote in in the thread, but it odes not work in that way anyway...
2
Hi, again an error from me, but it still doesnt work.

3
I said try:
Code:
If År = 2016 + j [COLOR=#ff0000]And[/COLOR] Me.År.Value = "Februari" Then
and this is what you put in your code:
Code:
If År = 2016 + j [COLOR=#ff0000]Then And[/COLOR] Me.Månad.Value = "Februari" Then

This method works for me
Code:
Private Sub År_Change()
    Dim j As Integer
    Application.EnableEvents = False
        Dag.Clear
    Application.EnableEvents = True
    For j = 0 To 100 Step 4
        If År = (2016 + j) And Månad = "Februari" Then
            Call Månad_skottår
        End If
    Next j
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,582
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top