Jump to content

Matriz Magica 3X3 Soma Sempre 15


sorel

Recommended Posts

preciso que alguem que saiba ativar a macro é sua a matriz,sim claro

   Sub MG3()

Dim Board As Range
Dim cel As Range
Dim cr As Range

Set Board = Selection

If Board.Rows.Count = Board.Columns.Count And Board.Rows.Count > 2 And Board.Rows.Count Mod 2 = 1 Then

Board.Cells.ClearContents
Set cel = Board.Cells(1, Int(Board.Columns.Count / 2) + 1)
cel.Value = 1


For i = 2 To Board.Cells.Count

If cel.Row() = 1 And cel.Column() <> Board.Columns.Count Then
Set cr = Board.Cells(Board.Rows.Count, cel.Column() + 1)
ElseIf cel.Row() = 1 And cel.Column() = Board.Columns.Count Then
Set cr = Board.Cells(Board.Rows.Count, 1)
ElseIf cel.Column() = Board.Columns.Count Then
Set cr = Board.Cells(cel.Row() - 1, 1)
Else
Set cr = cel.Offset(-1, 1)
End If

If cr.Value = vbNullString Then
Set cel = cr
Else
Set cel = cel.Offset(1)
End If

cel.Value = i

Next i
Else
MsgBox "Invalid Range"
End If

End Sub

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...