I have code I am developing where source data exists from column A to L starting at row 7. Separately, an output field based on that data exists in column M.
Goals of Code:
1) Import all data into an Array named "DataSet"
2) If any data exists in column M:
2a) Delete all data including output field in column M.
2b) Replace the original data in columns A through L.
Assumptions/Setup required for Code to Work:
1) Worksheets copied from have values in A1:A6 and M1:M6 (required for CountA as used).
Code:
Why is it not working to assign the DataSet Array back exactly into the range it came from?
Goals of Code:
1) Import all data into an Array named "DataSet"
2) If any data exists in column M:
2a) Delete all data including output field in column M.
2b) Replace the original data in columns A through L.
Assumptions/Setup required for Code to Work:
1) Worksheets copied from have values in A1:A6 and M1:M6 (required for CountA as used).
Code:
VBA Code:
Sub Sample_2D_Array()
'ADDRESS SOURCE WORKSHEET'
Dim SheetName As String
SheetName = ActiveSheet.Name
'COPY AND PASTE DATASET'
Dim DataRows As Integer
Dim DataSet As Variant
'Import DataSet data into an array'
DataRows = Application.CountA(Range("A:A"))
DataSet = Range("A7:L" & DataRows)
'
Worksheets(SheetName).Activate
If Application.CountA(Range("M:M")) = 6 Then
'Do nothing - there is no old data'
Else 'Delete the helper column data'
Rows("7:" & Application.CountA(Range("M:M"))).EntireRow.Delete
ActiveSheet.Range("A7:L" & DataRows) = DataSet()
End If
End Sub
Why is it not working to assign the DataSet Array back exactly into the range it came from?