Let me start by apologising in advance for any mistakes in forum etiquette or broken rules, as well as incorrect use of technical terms as I'm still learning slowly.
To summarise, I'm trying to build a sheet that pulls data from a referenced location to a specified cell location based on a drop-down selection made by the user.
Sub retrieve_data()
Dim LR As Long
LR = orderLog2.Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Application.ScreenUpdating = False
Application.EnableEvents = False
Sheets("search").UsedRange.Offset(2, 0).ClearContents
With Sheets("orderLog2")
.AutoFilterMode = False
.Range("A2:D" & LR).AutoFilter Field:=1, Criteria1:= _
Sheets("search").Range("C5").Value
.UsedRange.Offset(0, 0).SpecialCells(xlVisible).Copy
Sheets("search").Range("E7").PasteSpecial
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
So in a nutshell, I have a table of data on sheet "orderLog2" (columns A to D) and a drop down list on sheet "search". I was hoping that if a user selects a username from the drop down list (located in cell C5), then automatically all of the relevant data from sheet "orderLog2" will be copied over to sheet "search", cell E7.
Here's the code inserted into sheet "search":
Option Explicit
Private Sub dropdownselection(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$C$5" Then
Application.EnableEvents = False
Call retrieve_data
Application.EnableEvents = True
End If
End Sub
Lines: " LR = orderLog2.Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row "
is what's causing the run-time error, I assumed that LR is defined correctly and can be used for reference.
If I'm missing any importing info for you guys please feel free to let me know, any help or advice would be massively appreciated.