I am trying to have my code select a cell then use .End(xlDown).Select then Selection.Copy to copy a data set but I am having trouble getting my code to select the first cell using variables within my loop. I know my syntax is off on the range function but I am not sure where. Any help would be greatly appreciated.
Sub Copy_Function_Data()
Dim Target As String
Dim X As Integer
Dim Y As Integer
Dim Target_2 As String
Dim Last_Row3 As Integer
Dim Last_Column3 As Integer
Dim Title_Count As Integer
Dim Country_Count As Integer
Dim Total_Count As Integer
Dim Title_Column As Long
Dim Country_Column As String
Y = ActiveWorkbook.Worksheets("Calculations").Range("B2", Worksheets("Calculations").Range("B2").End(xlDown)).Rows.Count
For X = 1 To Y
Sheets("Calculations").Select
Target = Range("B2").Offset(X, 0)
ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = "TempData"
Worksheets("TempData").Range("A1").Value = Target
ActiveSheet.Range("A1").Select
Selection.Replace What:="Open Position - ", Replacement:=" ", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Target_2 = Worksheets("TempData").Range("A1")
ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = (Target_2)
Sheets("Raw Data").Select
Selection.AutoFilter
ActiveSheet.Range("$B$1:$Z$10000").AutoFilter Field:=5, Criteria1:= _
(Target)
Range("B1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets(Target_2).Select
Range("B20").Select
ActiveSheet.Paste
Total_Count = ActiveWorkbook.Worksheets(Target_2).Range("B20", Worksheets(Target_2).Range("B20").End(xlDown)).Rows.Count
Last_Row3 = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Last_Column3 = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
Title_Column = Cells.Find(What:="Title", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Column
Country_Column = Cells.Find(What:="Country", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Column
'************* This is where I need to add the code to copy and paste the range
Sheets("TempData").Delete
Next X
End Sub
Range("A1")
orcells(1,2)
, don't mix them unless you understand what you are doing.Cells
command takes numbers as parameters, not strings. So in your case, the first row should be something likeCells(20, Title_Column).Select