1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Sub tableau()
'create an excel file with one worksheet Result'
Dim MyExcel As Excel.Application
Dim New_Workbook As Excel.Workbook
Dim filename As String
Dim path As String
Dim Fcell As String
Dim Scell As String
path = "C:\Users\PC\Dropbox\IUM\Bachelor\VBA\"
filename = "result.xlsx"
Set MyExcel = CreateObject("Excel.Application")
Set New_Workbook = MyExcel.Workbooks.Add
New_Workbook.Sheets(1).Name = "Result"
New_Workbook.SaveAs path & filename
New_Workbook.Close
MyExcel.Quit
Fcell = InputBox("Select a first cell")
Scell = InputBox("Select a second cell")
Range(Fcell, Scell).Formula = "=Rand()"
Range(Fcell, Scell).Select
selection.Value = ActiveCell.Value ^ 2
selection.Copy
Sheets.Add After:=ActiveSheet
Sheets(2).Name = "Square Matrix"
ActiveSheet.Paste
End Sub |
Partager