Loop problem

Leffe23

New Member
Joined
Sep 23, 2011
Messages
1
Hello,

I'm relatively new to VBA. Nonetheless i'm building a pretty big app.
I have 20 comboboxes with values stored in it. So far so good.
Let's consider the content of the combobox: lefevere, name2, name3, name4. All data is stored in sheet 1. For example all data for "lefevere" is stored in row 3. Name2 in row 4 etc...
Whenever i chose in Driver3ComboBox "Lefevere" he has to export to the ranges below in the code. I could write 20 If Statements for every combobox and for four names it would be doable. But what if had 100 names? I hope and i'm almost sure that for this kind of problem a loop exists?
Every help is very much appreciated. Thanks a lot guys!

Code:
If Driver1ComboBox.Value = "Lefevere" Then
    Sheets(4).Range("B6").Value = Driver1ComboBox.Value
    Sheets(4).Range("A6").Value = Sheets(1).Range("A3")
    Sheets(4).Range("D6").Value = Sheets(1).Range("B3")
    Sheets(4).Range("B6").Value = Sheets(1).Range("C3")
    Sheets(5).Range("A34").Value = Sheets(1).Range("C3")
    Sheets(5).Range("C34").Value = Sheets(1).Range("B3")
    Sheets(5).Range("E34").Value = Sheets(1).Range("A3")
    Sheets(5).Range("F34").Value = Sheets(1).Range("D3")
    Sheets(5).Range("G34").Value = Sheets(1).Range("F3")
    Sheets(6).Range("B8").Value = Sheets(1).Range("C3")
    Sheets(6).Range("C8").Value = Sheets(1).Range("B3")
    Sheets(6).Range("D8").Value = Sheets(1).Range("A3")
    Sheets(6).Range("E8").Value = Sheets(1).Range("D3")
    Sheets(6).Range("F8").Value = Sheets(1).Range("L3")
    Sheets(6).Range("G8").Value = Sheets(1).Range("M3")
    Sheets(6).Range("H8").Value = Sheets(1).Range("E3")
    Sheets(6).Range("I8").Value = Sheets(1).Range("F3")
    Sheets(6).Range("J8").Value = Sheets(1).Range("H3")
    Sheets(6).Range("K8").Value = Sheets(1).Range("O3")
    Sheets(6).Range("K8").Value = Sheets(1).Range("Q3")
    Sheets(8).Range("A11").Value = Sheets(1).Range("A3")
    Sheets(8).Range("B11").Value = Sheets(1).Range("C3")
    Sheets(8).Range("E11").Value = Sheets(1).Range("D3")
End If
If Driver2ComboBox.Value = "Lefevere" Then
    Sheets(4).Range("B7").Value = Driver2ComboBox.Value
    Sheets(4).Range("A7").Value = Sheets(1).Range("A3")
    Sheets(4).Range("D7").Value = Sheets(1).Range("B3")
    Sheets(4).Range("B7").Value = Sheets(1).Range("C3")
    Sheets(5).Range("A35").Value = Sheets(1).Range("C3")
    Sheets(5).Range("C35").Value = Sheets(1).Range("B3")
    Sheets(5).Range("E35").Value = Sheets(1).Range("A3")
    Sheets(5).Range("F35").Value = Sheets(1).Range("D3")
    Sheets(5).Range("G35").Value = Sheets(1).Range("F3")
    Sheets(6).Range("B9").Value = Sheets(1).Range("C3")
    Sheets(6).Range("C9").Value = Sheets(1).Range("B3")
    Sheets(6).Range("D9").Value = Sheets(1).Range("A3")
    Sheets(6).Range("E9").Value = Sheets(1).Range("D3")
    Sheets(6).Range("F9").Value = Sheets(1).Range("L3")
    Sheets(6).Range("G9").Value = Sheets(1).Range("M3")
    Sheets(6).Range("H9").Value = Sheets(1).Range("E3")
    Sheets(6).Range("I9").Value = Sheets(1).Range("F3")
    Sheets(6).Range("J9").Value = Sheets(1).Range("H3")
    Sheets(6).Range("K9").Value = Sheets(1).Range("O3")
    Sheets(6).Range("K9").Value = Sheets(1).Range("Q3")
    Sheets(8).Range("A12").Value = Sheets(1).Range("A3")
    Sheets(8).Range("B12").Value = Sheets(1).Range("C3")
    Sheets(8).Range("E12").Value = Sheets(1).Range("D3")
End If
If Driver3ComboBox.Value = "Lefevere" Then
    Sheets(4).Range("B8").Value = Driver3ComboBox.Value
    Sheets(4).Range("A8").Value = Sheets(1).Range("A3")
    Sheets(4).Range("D8").Value = Sheets(1).Range("B3")
    Sheets(4).Range("B8").Value = Sheets(1).Range("C3")
    Sheets(5).Range("A36").Value = Sheets(1).Range("C3")
    Sheets(5).Range("C36").Value = Sheets(1).Range("B3")
    Sheets(5).Range("E36").Value = Sheets(1).Range("A3")
    Sheets(5).Range("F36").Value = Sheets(1).Range("D3")
    Sheets(5).Range("G36").Value = Sheets(1).Range("F3")
    Sheets(6).Range("B10").Value = Sheets(1).Range("C3")
    Sheets(6).Range("C10").Value = Sheets(1).Range("B3")
    Sheets(6).Range("D10").Value = Sheets(1).Range("A3")
    Sheets(6).Range("E10").Value = Sheets(1).Range("D3")
    Sheets(6).Range("F10").Value = Sheets(1).Range("L3")
    Sheets(6).Range("G10").Value = Sheets(1).Range("M3")
    Sheets(6).Range("H10").Value = Sheets(1).Range("E3")
    Sheets(6).Range("I10").Value = Sheets(1).Range("F3")
    Sheets(6).Range("J10").Value = Sheets(1).Range("H3")
    Sheets(6).Range("K10").Value = Sheets(1).Range("O3")
    Sheets(6).Range("K10").Value = Sheets(1).Range("Q3")
    Sheets(8).Range("A13").Value = Sheets(1).Range("A3")
    Sheets(8).Range("B13").Value = Sheets(1).Range("C3")
    Sheets(8).Range("E13").Value = Sheets(1).Range("D3")
End If
If Driver4ComboBox.Value = "Lefevere" Then
    Sheets(4).Range("B9").Value = Driver4ComboBox.Value
    Sheets(4).Range("A9").Value = Sheets(1).Range("A3")
    Sheets(4).Range("D9").Value = Sheets(1).Range("B3")
    Sheets(4).Range("B9").Value = Sheets(1).Range("C3")
    Sheets(5).Range("A37").Value = Sheets(1).Range("C3")
    Sheets(5).Range("C37").Value = Sheets(1).Range("B3")
    Sheets(5).Range("E37").Value = Sheets(1).Range("A3")
    Sheets(5).Range("F37").Value = Sheets(1).Range("D3")
    Sheets(5).Range("G37").Value = Sheets(1).Range("F3")
    Sheets(6).Range("B11").Value = Sheets(1).Range("C3")
    Sheets(6).Range("C11").Value = Sheets(1).Range("B3")
    Sheets(6).Range("D11").Value = Sheets(1).Range("A3")
    Sheets(6).Range("E11").Value = Sheets(1).Range("D3")
    Sheets(6).Range("F11").Value = Sheets(1).Range("L3")
    Sheets(6).Range("G11").Value = Sheets(1).Range("M3")
    Sheets(6).Range("H11").Value = Sheets(1).Range("E3")
    Sheets(6).Range("I11").Value = Sheets(1).Range("F3")
    Sheets(6).Range("J11").Value = Sheets(1).Range("H3")
    Sheets(6).Range("K11").Value = Sheets(1).Range("O3")
    Sheets(6).Range("K11").Value = Sheets(1).Range("Q3")
    Sheets(8).Range("A14").Value = Sheets(1).Range("A3")
    Sheets(8).Range("B14").Value = Sheets(1).Range("C3")
    Sheets(8).Range("E14").Value = Sheets(1).Range("D3")
End If
If Driver5ComboBox.Value = "Lefevere" Then
    Sheets(4).Range("B10").Value = Driver5ComboBox.Value
    Sheets(4).Range("A10").Value = Sheets(1).Range("A3")
    Sheets(4).Range("D10").Value = Sheets(1).Range("B3")
    Sheets(4).Range("B10").Value = Sheets(1).Range("C3")
    Sheets(5).Range("A38").Value = Sheets(1).Range("C3")
    Sheets(5).Range("C38").Value = Sheets(1).Range("B3")
    Sheets(5).Range("E38").Value = Sheets(1).Range("A3")
    Sheets(5).Range("F38").Value = Sheets(1).Range("D3")
    Sheets(5).Range("G38").Value = Sheets(1).Range("F3")
    Sheets(6).Range("B12").Value = Sheets(1).Range("C3")
    Sheets(6).Range("C12").Value = Sheets(1).Range("B3")
    Sheets(6).Range("D12").Value = Sheets(1).Range("A3")
    Sheets(6).Range("E12").Value = Sheets(1).Range("D3")
    Sheets(6).Range("F12").Value = Sheets(1).Range("L3")
    Sheets(6).Range("G12").Value = Sheets(1).Range("M3")
    Sheets(6).Range("H12").Value = Sheets(1).Range("E3")
    Sheets(6).Range("I12").Value = Sheets(1).Range("F3")
    Sheets(6).Range("J12").Value = Sheets(1).Range("H3")
    Sheets(6).Range("K12").Value = Sheets(1).Range("O3")
    Sheets(6).Range("K12").Value = Sheets(1).Range("Q3")
    Sheets(8).Range("A15").Value = Sheets(1).Range("A3")
    Sheets(8).Range("B15").Value = Sheets(1).Range("C3")
    Sheets(8).Range("E15").Value = Sheets(1).Range("D3")
End If
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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