* thats supposed to be 'after UNLOADING userform'... (not 'uploading') sorry, my bad.
when the form is opened, it asks for a date range. when a commandbutton is selected, it gets the data from a worksheet ("Seatex Incident Log") and then copies it and pastes it onto a different worksheet ("REPORTS"), but I cant get it to stay on the worksheet REPORTS when the form closes... If I remove the 'unload' command from the form, then it works (of course the form is still on the screen covering up most of the worksheet.)
I used this same technique and code on another workbook, but it is executed from a commandbutton on a worksheet and not a userform like this one is doing. What am I missing?? Here is the code:
This is the code for the command button that executes the action of filtering the data from the main worksheet ("Seatex Incident Log") , copying it, and then pasting it onto another worksheet ("REPORTS)... which is the worksheet that I need the focus to be set to.
I ve already tried moving around this part of the code
to different places (before or after 'unload me') and it doesnt matter what where i put or what i try... after the form unloads no matter what it always going back to the "Seatex Incident Log" worksheet.
when the form is opened, it asks for a date range. when a commandbutton is selected, it gets the data from a worksheet ("Seatex Incident Log") and then copies it and pastes it onto a different worksheet ("REPORTS"), but I cant get it to stay on the worksheet REPORTS when the form closes... If I remove the 'unload' command from the form, then it works (of course the form is still on the screen covering up most of the worksheet.)
I used this same technique and code on another workbook, but it is executed from a commandbutton on a worksheet and not a userform like this one is doing. What am I missing?? Here is the code:
This is the code for the command button that executes the action of filtering the data from the main worksheet ("Seatex Incident Log") , copying it, and then pasting it onto another worksheet ("REPORTS)... which is the worksheet that I need the focus to be set to.
I ve already tried moving around this part of the code
Code:
ActiveWorkbook.Worksheets("REPORTS").Activate
ActiveWorkbook.Worksheets("REPORTS").Visible = True
ActiveWorkbook.Worksheets("REPORTS").Range("A4").Select
to different places (before or after 'unload me') and it doesnt matter what where i put or what i try... after the form unloads no matter what it always going back to the "Seatex Incident Log" worksheet.
Code:
[COLOR=#008000]' *****************************************************[/COLOR][COLOR=#008000]****************************************************[/COLOR][COLOR=#008000]
' CODE FOR SELECTING JUST THE RECORDS ON THE WORKSHEET "SEATEX INCIDENT LOG" THAT FALL WITHIN THE DATE RANGE THAT WAS PREVISOULY SELECTED ON THE USERFORM[/COLOR]
Private Sub cmdGetReport_Click()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Dim rCol As Long
Dim ws As Worksheet
Dim W1Startdate As String, W1Enddate As String
[COLOR=#008000]'set object variable to worksheet[/COLOR]
Set ws = ThisWorkbook.Worksheets("Seatex Incident Log")
W1Startdate = Me.txtDateBox2.Value [COLOR=#008000] ' "FROM" date[/COLOR]
W1Enddate = Me.txtDateBox3.Value [COLOR=#008000]' "TO" date[/COLOR]
rCol = Sheets("Seatex Incident Log").UsedRange.Rows.Count
With ws
ActiveWorkbook.Worksheets("Seatex Incident Log").Activate
.Sort.SortFields.Clear
With .Range(Cells(17, 1), Cells(rCol, 29))
[COLOR=#008000]'clear filter[/COLOR]
.AutoFilter
.AutoFilter Field:=2, _
Criteria1:=">=" & CLng(DateValue(W1Startdate)), _
Criteria2:="<=" & CLng(DateValue(W1Enddate))
End With
End With
[COLOR=#008000]' ****************************************************[/COLOR][COLOR=#008000]****************************************************[/COLOR][COLOR=#008000]*[/COLOR][COLOR=#008000]
[/COLOR][COLOR=#008000]' ****************************************************[/COLOR][COLOR=#008000]****************************************************[/COLOR][COLOR=#008000]*[/COLOR][COLOR=#008000]
' CODE FOR COPYING ALL THE VISIBLE ROWS THAT HAVE BEEN FILTERED DOWN TO AFTER THE DATE QUERY AND THE INCIDENT TYPE QUERY HAS BEEN RAN AND PASTING_
'ALL THAT TO THE HIDDEN SHEET "REPORTS"
[/COLOR]
ActiveWorkbook.Worksheets("REPORTS").Activate
ActiveSheet.Range("A4").EntireRow.Select
ActiveSheet.Range(Selection, Selection.End(xlDown)).Select
Selection.Clear
[COLOR=#008000]' ****************************************************[/COLOR][COLOR=#008000]****************************************************[/COLOR][COLOR=#008000]*[/COLOR]
ActiveWorkbook.Worksheets("Seatex Incident Log").Activate
ActiveWorkbook.Worksheets("Seatex Incident Log").Range(Cells(18, 1), Cells(rCol, 29)).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
[COLOR=#008000]' ****************************************************[/COLOR][COLOR=#008000]****************************************************[/COLOR][COLOR=#008000]*[/COLOR]
ActiveWorkbook.Worksheets("REPORTS").Activate
ActiveWorkbook.Worksheets("REPORTS").Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Unload Me
ActiveWorkbook.Worksheets("REPORTS").Activate
ActiveWorkbook.Worksheets("REPORTS").Visible = True
ActiveWorkbook.Worksheets("REPORTS").Range("A4").Select
End Sub
Last edited: