Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting cell in VB in excel

Status
Not open for further replies.

llynch

Technical User
Jun 11, 2010
1
IE
Ok I now this might seem simple, but I do in fact have more of a code but if I run this alone I still get run-time error 1004 (highlighting range line)

Private Sub CommandButton1_Click()
Sheets("Control").Select
Range("B51:D51").Select
End Sub

Anyone have any idea why this might be happening.
It works fine if I record a macro and play it, but if I click on command button i get error message. (just incase someone might suggest a tab being named incorrectly)

If it makes a difference B51:D51 is a merged cell.

Selecting a cell/range is the most basic of steps in VB and a really necessary one, and I cant get it to work.
Is there a box that might be ticked in options incorrectly, or something.

Appreciate any help anyone has on this.
 


Hi,

Always fully quallify...
Code:
Private Sub CommandButton1_Click()
    Sheets("Control").Select
    Sheets("Control").Range("B51:D51").Select
End Sub
But there are very few circumstances where I would recommend using the Activate or Select methods.

Also, please post future VBA questions in forum707.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top