Multiple Comboboxes

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:

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,681
Office Version
365
Platform
Windows
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:

MrThor

New Member
Joined
Aug 13, 2018
Messages
36
Hi, actually, I just forgot to wrote in in the thread, but it odes not work in that way anyway...
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,681
Office Version
365
Platform
Windows
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:

MrThor

New Member
Joined
Aug 13, 2018
Messages
36
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
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,681
Office Version
365
Platform
Windows
Are the 3 comboboxes on a userform?
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,681
Office Version
365
Platform
Windows
: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:

Forum statistics

Threads
1,082,275
Messages
5,364,180
Members
400,785
Latest member
Mahar92

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top