Peter Chan
asked on
Problem to select
Hi,
I get
due to Select line (last 4th line) below. Why?
Windows(Window0).Activate
Dim RowID1 As Integer
RowID1 = 2
Do While True
If Trim(Worksheets("Utilizati on-PO-List ").Cells(R owID1, 2).Value) = "" And Trim(Worksheets("Utilizati on-PO-List ").Cells(R owID1, 4).Value) = "" And Trim(Worksheets("Utilizati on-PO-List ").Cells(R owID1, 5).Value) = "" And Trim(Worksheets("Utilizati on-PO-List ").Cells(R owID1, 6).Value) = "" Then
Exit Do
End If
RowID1 = RowID1 + 1
Loop
If RowID1 > 1 Then
Worksheets("Utilization-PO -List").Un protect Password:="hkg1317"
Worksheets("Utilization-PO -List").Ce lls(RowID1 , 1).Select
Windows(Current_Book).Acti vate
Worksheets("Utilization-PO -List").Un protect Password:="hkg1317"
Worksheets("Utilization-PO -List").Ra nge(Range0 ).Copy
...
I get
due to Select line (last 4th line) below. Why?
Windows(Window0).Activate
Dim RowID1 As Integer
RowID1 = 2
Do While True
If Trim(Worksheets("Utilizati
Exit Do
End If
RowID1 = RowID1 + 1
Loop
If RowID1 > 1 Then
Worksheets("Utilization-PO
Worksheets("Utilization-PO
Windows(Current_Book).Acti
Worksheets("Utilization-PO
Worksheets("Utilization-PO
...
What is the value of RowID1 when you get the error? You can check easily by clicking "Debug" in the error message, then placing the cursor over the variable.
my guess would be that is is not the active sheet -- that must be done first
ASKER
Wayne,
The value of RowID1 is 5, when the error happens.
The value of RowID1 is 5, when the error happens.
ASKER
Crystal,
Any advice to adjust the codes in above?
Any advice to adjust the codes in above?
When that error occurs, that means the correct workbook is not your active workbook from which you want to select a range.
To check this, use Debug.Print to see the state of the activeworkbook in the Immediate Window.
Run the code by adding following extra lines and when you get and error, debug and press Ctrl+G to open the immediate window and see if you are on the correct workbook and the Range0 is a valid range you are trying to select.
To check this, use Debug.Print to see the state of the activeworkbook in the Immediate Window.
Run the code by adding following extra lines and when you get and error, debug and press Ctrl+G to open the immediate window and see if you are on the correct workbook and the Range0 is a valid range you are trying to select.
Windows(Current_Book).Activate
Debug.Print ActiveWorkbook.Name 'To see which workbook is active at present
Debug.Print Range(Range0).Address 'To know if Range0 is a valid range
Worksheets("Utilization-PO-List").Unprotect Password:="hkg1317"
Worksheets("Utilization-PO-List").Range(Range0).Copy
ASKER
But the error is due to this line
Worksheets("Utilization-PO-List").Cells(RowID1, 1).Select
ASKER
I put this
to the line on which the error happens, and the Workbook is the current one which I expect
Debug.Print ActiveWorkbook.Name
to the line on which the error happens, and the Workbook is the current one which I expect
ASKER
I put this
before the line on which the error happens, and the Workbook is the current one which I expect
Debug.Print ActiveWorkbook.Name
before the line on which the error happens, and the Workbook is the current one which I expect
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change this...
...to this...
Worksheets("Utilization-PO-List").Unprotect Password:="hkg1317"
Worksheets("Utilization-PO-List").Cells(RowID1, 1).Select
...to this...
With Worksheets("Utilization-PO-List")
.Select
.Unprotect Password:="hkg1317"
.Cells(RowID1, 1).Select
End With
And if this is the case, try to select the sheet first before selecting a cell on that sheet.
Worksheets("Utilization-PO -List").Se lect
Cells(RowID1, 1).Select
Worksheets("Utilization-PO
Cells(RowID1, 1).Select