Please tell me how, using cells
, to determine if the cell is merged with another. In fact, I need to unload the names of the rows into the form (in the ComboBox), but these names refer to several rows at once (that is, the cells are merged vertically).
1 answer
The task is not completely clear. Check if the cell is merged with another (s):
If Worksheets("ΠΠΈΡΡ1").Cells(1, 3).MergeCells Then MsgBox "Π’Π°ΠΊΠΈ Π΄Π°!"
When merging, the value of the cells, except the left top, is lost. In this case, to create a list for the ComboBox, it is not necessary to check whether the cells are merged; it is enough to check the cells for the presence of data. The code that creates the list of the form element:
Private Sub UserForm_Initialize() Dim Rng As Range Dim n ' ΡΠΎΠ·Π΄Π°ΡΡ Π²ΡΠΏΠ°Π΄Π°ΡΡΠΈΠΉ ΡΠΏΠΈΡΠΎΠΊ With Worksheets("ΠΠΈΡΡ1") Set Rng = .Range("C1:H4") ' ΠΏΡΠΈΡΠ²ΠΎΠΈΡΡ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½ "ΡΠ°ΠΏΠΊΠΈ" ΡΠ°Π±Π»ΠΈΡΡ End With ' ΡΠΈΠΊΠ» ΠΏΠΎ ΡΡΠ΅ΠΉΠΊΠ°ΠΌ For Each n In Rng.Value If n <> "" Then ' Π΅ΡΠ»ΠΈ Π² ΡΡΠ΅ΠΉΠΊΠ΅ Π΅ΡΡΡ Π΄Π°Π½Π½ΡΠ΅ Me.ComboBox1.AddItem n ' Π΄ΠΎΠ±Π°Π²ΠΈΡΡ ΡΡΡΠΎΠΊΡ Π² ΡΠΏΠΈΡΠΎΠΊ End If Next n End Sub
PS In the calculation tables, try not to merge cells if possible, there may be problems with calculations.
|