Thanks you AlphaFrog!! I so agree that 99% of the problems with communicating in writing is EFFECTIVELY EXPLAINING THE ISSUE.
My issue has been finally resolved and I would like to post the code...ahhh now I see the code tag icon.
I had a long list of data occupying columns A through F, 40,000 rows long. "Regular VBA Looping Code" took about 5 minutes to run - LONG TIME!!
I simply wanted to use an array to read all the data in from the main worksheet, then extract only columns A, B, C, when condition in column D was met (here it was a year)
An InputBox was used to name the year one wanted to extract, as well as the new worksheet name the extracted data would be copied to.
I have a "smattering" of comments throughout the code so hopefully it will be much easier to decipher? Hope you find useful?
Option Explicit
Option Base 1
Sub MyFirstArray()
Dim bigArray As Variant
Dim Rng As Range
Dim i As Integer
Dim j As Integer
Dim Wks As Worksheet
Dim NewWorkSheetName As String
Dim YearToInput As Variant
Dim myThirdColumn As Variant
Dim facilityID As Range
Dim triChemical As Range
Dim myData As Variant
Dim LastUsedRow As Long
Dim NextRow As Long
Application.ScreenUpdating = False
'Determine the last row where there is data of the original dataset, can use because all columns are same length.
LastUsedRow = Range("A" & Rows.Count).End(xlUp).Row
'Set the variable Wks to be the name of the worksheet on which the original data is located
Set Wks = ActiveWorkbook.ActiveSheet
'Input the reporting year of the data you want to extract - Input boxes return a STRING so convert this one to a value since its a year
YearToInput = InputBox("Enter the first year you want to extract to a new worksheet, then click OK or Enter")
YearToInput = Val(YearToInput)
'Use an inputbox to name the worksheet on which you want to paste that year's information
NewWorkSheetName = InputBox("Normally enter the year, will autogenerate, then click OK or Enter", "Name the New Worksheet")
Sheets.Add.Name = NewWorkSheetName
'Go back and make the original data sheet the active worksheet the newly added sheet is now the active sheet
Wks.Activate
With ActiveSheet
Set Rng = Range("A1:D" & LastUsedRow)
'Store all the elements, i.e., data, into bigArray to test year in question
bigArray = Rng.Value
NextRow = 1
'Use entire data range to test for the year to be extracted
For i = 1 To UBound(bigArray)
'Test to see which year to extract data from the main worksheet
If bigArray(i, 3) = YearToInput Then
Worksheets(NewWorkSheetName).Cells(NextRow, "A") = bigArray(i, 1)
Worksheets(NewWorkSheetName).Cells(NextRow, "B") = bigArray(i, 2)
Worksheets(NewWorkSheetName).Cells(NextRow, "C") = bigArray(i, 4)
NextRow = NextRow + 1
End If
Next i
Worksheets(NewWorkSheetName).Columns("A:C").AutoFit
Application.CutCopyMode = False
End With
Application.ScreenUpdating = True
End Sub
Bookmarks