I'm trying to write this code to assist in data analysis for my dissertation but i get this error at a particular line:
Set RankValue = Sheets(1).Range("D2:D & LastRow")
I'm new to VBA but i have tried all options to present the right syntax as can be in the code below.
Private Sub Timeframe()
Dim LastRow As Long
Dim Timeframe As New Collection
Dim RowNumber As Long
Dim RankValue As Range
Dim Cell As Range
Dim Item As Variant
LastRow = Sheet1.Cells(Rows.Count, 4).End(xlUp).Row
Debug.Print LastRow
Sheet1.Range("F1").Value = "Timeframe"
Sheet1.Range("F2:F" & LastRow).Clear
RowNumber = 1
'Set RankValue = Sheet1.Range("D2:D")
'Set RankValue = Sheet1.Range("D2:D & LastRow")
'Set RankValue = Application.Workbooks("LoopCode2.xlsm").Worksheets("Sheet1").Range("D2:D & LastRow")
'Set RankValue = Application.Workbooks("LoopCode2.xlsm").Worksheets("Sheet1").Range("D2:D")
'Set RankValue = Worksheets("Sheet1").Range("D2:D & LastRow")
'Set RankValue = Sheets("Sheet1").Range("D2:D & LastRow")
'Set RankValue = Sheets("Sheet1").Range("D2:D")
'Set RankValue = Sheets("Sheet1").Range("D2:D & LastRow")
'Set RankValue = Worksheets(1).Range("D2:D & LastRow")
Set RankValue = Sheets(1).Range("D2:D & LastRow")
For Each Cell In RankValue
On Error Resume Next
Timeframe.Add Item:=Cell.Value, Key:=CStr("Cell.Value")
On Error GoTo 0
Next Cell
Debug.Print LastRow
For Each Item In Timeframe
RowNumber = RowNumber + 1
Sheet1.Cells(RowNumber, 6) = Item.Value
Next Item
Set Timeframe = New Collection
End Sub
Grateful if you could assist me find what I'm doing wrong, and how can i fix it.