![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 18
|
What does the 'With' statement do?
Also, what is wrong with the code below? Private Sub Inputdata_Click() Worksheets("Input").Activate Cells(5, 3).Select If (ActiveCell.Value = "") Then Exit Sub Worksheets("Sheet2").Activate Cells(5, 4).Select ActiveCell.Value = 1 End Sub I get an error that says 'Select method of Range Class fails' and I dont know why. I am new to Visual Basic and I would appreciate anyone's help. Thanks Seri |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Quote:
With Range("A1") .Font.Size = 12 .Value = 1 .Copy Range("B1") End With It helps you not to write Range("A1") everytime because you will always point to that range. 2. What's wrong ? basically, nothing... I'm guessing you're using Excel 97, and InputData is a CommandButton that has the TakeFocus******* property set to TRUE. Change it to FALSE. 3. Try this code ! Private Sub Inputdata_Click() If Worksheets("Input").Cells(5, 3).Value = "" Then Exit Sub Worksheets("Sheet2").Cells(5, 4).Value = 1 End Sub As you can see, there's no need to Select or Activate ANYTHING in there ! |
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|