BF
OK, glad we got the VBA bit confirmed.
Using Jcis's suggestion, here is your OP, with indents.
I took the liberty to edit the Next statements by adding the
identifying "counter".
Code:
For x = lines_start To lines_limit
For y = coulumns_start To columns_limit
k = 0
For i = 1 To cond_nr
'verifying first possible value
vertically_available = yes 'vertically
For j = lines_start To lines_limit
If Sheet1.Cells(y, j) = possibleValues(i) Then
vertically_available = no
Exit For
End If
Next j
If vertically_available = yes And horizontally_available = yes Then
k = k + 1
finalValues(k) = possibleValues(i)
End If
End If
Next i
'randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
luck = CInt(Int((k - 1 + 1) * Rnd() + 1))
Sheet1.Cells(x, y) = finalValues(luck)
Next y
Next x
For starters, you seem to have an unmatched End If.
Such a situation will cause a crash, but the "reported error" is generally
unreliable .. usually something else is the issue.
See what happens if you fix that.
EDIT:
I just saw Opus's spot .. nice one .. 
I have also highlighted that in red.
Here, too, is the balance of your code from your post #3.
I also took the liberty to add some extra Dim lines (to eliminate
the horizontal scroll bar for ease of reading), but did not address
the issue that Jcis brought up .. you still need to fix that.
Code:
Private Sub CommandButton1_Click()
Dim finalValues(1 To 3), possibleValues(1 To 3), remainedValues(1 To 3) As String
Dim l, j, k, i, luck, x, y, lines_limit, columns_limit As Integer
Dim lines_start, columns_start As Integer
Dim vecin_stanga, vecin_dreapta, vecin_sus, vecin_jos As Integer
Dim cond_nr As Integer
Dim stanga_value, dreapta_value, sus_value, jos_value As String
Dim vertically_available, horizontally_available As String
' set vars
lines_start = 2
columns_start = 2
lines_limit = 4
columns_limit = 4
cond_nr = 3
possibleValues(1) = "Deftones"
possibleValues(2) = "Tool"
possibleValues(3) = "Disturbed"
< ... see code snippet above ... >
MsgBox "done "
End Sub
Finally, a suggestion to minimize typo's of the kind that Opus caught ...
- Always use a few CAPITAL letters when you Dim your variable names.
- Thereafter, when you type the variable name in lower case, the VBA Editor
will automatically capitalize it for you. - This is a visual clue .. if you type some var name and no capitals appear
>> oops !
So, something like this (incomplete list, but does use Jcis's suggestion)
Code:
Dim Lines_Limit As Integer
Dim Columns_Limit As Integer
Dim Lines_Start As Integer
Dim Columns_Start As Integer
Dim Cond_NR As Integer
Spoo