View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Range().Select not working

The problem was that when you have code behind a worksheet (like your
commandbutton1_click module), any unqualified ranges belong to the sheet that
contains the code:

So "Range("B1").select" was refering to the sheet with the code.

You selected "employee summary" first. So that was the activesheet.

But you can only select cells on the activesheet. So it blew up.

You could have done this (very ugly):

Private Sub CommandButton1_Click() 'Employee Detail Button

' Lookup selected employee and load data on Employee Summary tab

Dim EmpLookup As Variant
EmpLookup = ActiveCell.Value
Sheets("Employee Summary").Select
sheets("employee summary").Range("B1").Select
ActiveCell.Value = EmpLookup
Call Load_Emp_Summary
End Sub


But it's much better not to select anything.

sheets("employee summary").range("b1").value = emplookup


clmarquez wrote:

Please help! I have a command button on a worksheet, that when the user
highlights a cell with an employee name in it and presses the button, it
takes them to a different worksheet, inputs the highlighted cell's value
into cell B1 (which is linked to a combobox) and then calls a macro.
The code for the command button is as follows:

Private Sub CommandButton1_Click() 'Employee Detail Button

' Lookup selected employee and load data on Employee Summary tab

Dim EmpLookup As Variant
EmpLookup = ActiveCell.Value
Sheets("Employee Summary").Select
On Error Resume Next
Range("B1").Select
ActiveCell.Value = EmpLookup
Call Load_Emp_Summary

End Sub

My problem is that when the sub is stepped through, the
Range("B1").Select line does not work (everything else does), and so
the name gets inputted into whatever cell happens to be highlighted in
the worksheet. Can anyone tell me why that line won't work? Is there
another way to force selection of cell B1? I am using Excel 2003...

Thanks,
Kez

--
clmarquez
------------------------------------------------------------------------
clmarquez's Profile: http://www.excelforum.com/member.php...o&userid=29386
View this thread: http://www.excelforum.com/showthread...hreadid=494049


--

Dave Peterson