MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Control toolbox button

  Asked By: Oscar    Date: Nov 17    Category: MS Office    Views: 1358

If you add a comman button in sheet one, and then write your code, it
only affects the parameters in sheet one. I need the command button to
affect multiple sheets. How do I modified my code so that the button
affects all sheets?



1 Answer Found

Answer #1    Answered By: Lena Moore     Answered On: Nov 17

You can refer to any sheet  - either by name or by index. Look at the
WorkSheets and sheets  collections (I think they both do the same thing).


Option Explicit

Private Sub CommandButton1_Click()
Worksheets(1).Range("a1").Value = 1
Worksheets(2).Range("a1").Value = 2
Sheets(1).Range("a2").Value = 1
Sheets(2).Range("a2").Value = 2
Sheets("Sheet1").Range("a3").Value = 1
Sheets("Sheet2").Range("a3").Value = 2
End Sub

Didn't find what you were looking for? Find more on Control toolbox button Or get search suggestion and latest updates.