0

I'm new programming at vba and I can't understand what's the difference between an actived cell and a selected cell.

I'm making a very simple example I found on internet about press a button and add the values of certain lines.

This is my example:

image1

When I press the button that says "Rellenar" I want the information about countries goes to dropdown menu.

I made this:

Private Sub CommandButton4_Click()

    Range("k6").Activate

    Do While Not IsEmpty(ActiveCell)

        micombo.AddItem ActiveCell.Value

        ActiveCell.Offset(1, 0).Activate

    Loop

End Sub

Where "k6" is the 1st cell where you can find information, but I tried to change the activate value to select value and the programm works exactly the same with both.

Can someone explain me the difference between both one?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 3
    You can select more than one cell but only one can be active. – Scott Craner Sep 05 '19 at 14:13
  • 3
    But one should avoid the use of `.Activate`, `ActiveCell`, `.Select` and `.Selected`. See [HERE](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) on how to avoid that. – Scott Craner Sep 05 '19 at 14:15
  • BTW: here are some example on how to load a combo box without using the above commands: https://stackoverflow.com/questions/42308318/how-do-i-populate-a-combobox-with-an-existing-array – Scott Craner Sep 05 '19 at 14:25

1 Answers1

1

From my understanding an Active cell is the cell the user is currently on. E.G the highlighted cell if you are in a spreadsheet.

A Selected cell is a cell that has been clicked. You can have more than one selected cell. (Usually by holding down CTRL and selecting multiple cells) However the only active cell is the one the user is currently on.

Another example for this is when you are selecting multiple images on your computer. If you click one then that's your active cell. Whereas if you click multiple then the clicked cells are "Selected" but only your most recent click is an active cell.

GhastlyCode
  • 248
  • 1
  • 11