View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Command button code

Hi Gary,

'-----------------
Using the same button I also need to insert some rows into the same
sheet the button is in, how would that be done?
'-----------------

To insert 10 rows try:

'=============
Private Sub CommandButton1_Click()
Dim SH As Worksheet
Dim Rng As Range
Const sStr As String = "ABC" '<<==== CHANGE

Set SH = ThisWorkbook.Sheets("Sheet2") '<<==== CHANGE
Set Rng = SH.Range("A1") '<<==== CHANGE
Rng.Value = sStr

SH.Range("A10").Resize(10).EntireRow.Insert
End Sub
'<<=============


Change the value 10 in the expression:

SH.Range("A10").Resize(10).EntireRow.Insert

to amend the number of rows to be inserted.


---
Regards,
Norman