Originally Posted by
bakerman2
Create Array in memory and write to worksheet in 1 go.
Sub Random_Array()
Dim square()
numrows = 20: numcols = 10
ReDim square(1 To numrows, 1 To numcols)
For i = 1 To numrows
For j = 1 To numcols
square(i, j) = 1 + Int(32 * Rnd())
Next j
Next i
With Range("A1")
.CurrentRegion.ClearContents
.Resize(numrows, numcols) = square
End With
End Sub
Hi there Bakerman2,
thanks for that, I think i've come up with almost what you've written, but i'm getting an error when running, can you spot where I've gone wrong?
Sub MAP_CREATOR()
Dim MapArray() As Byte
Dim SysType As Byte
Dim TheRange As Range
Dim CellsDown As Long, CellsAcross As Long
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
' Change these values
CellsDown = 5
CellsAcross = 5
' Redimension temporary array
ReDim MapArray(1 To CellsDown, 1 To CellsAcross)
' Set worksheet range
Set TheRange = Range(Cells(1, 1), Cells(CellsDown, CellsAcross))
For AR = 1 To CellsDown
For AC = 1 To CellsAcross
Randomize
MapArray(AR, AC) = (Int((32 - 1 + 1) * Rnd + 1))
Next AC
Next AR
With Range("A1")
.CurrentRegion.ClearContents
.Resize(CellsDown, CellsDown) = MapArray
End With
'TheRange.Value = MapArray
'Worksheets("MAP").Range("A1:CV100").Value = MapArray
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
runtimeerr.png
Bookmarks