Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Command button code

Hi all,

I have created a command button on a worksheet in an Excel 2003
workbook. I just need to assign some code to this button so that when
clicked, it will simply enter text into a cell in another worksheet in
the same workbook.

Sounds very easy to me, but I've not been able to figure it out yet,
or see any examples.

Can someone help me out please?

Thanks a lot.

Gary.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Command button code

Hi Gary,

Try something like:

'=============
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
End Sub
'<<=============


---
Regards,
Norman


"Gary" wrote in message
oups.com...
Hi all,

I have created a command button on a worksheet in an Excel 2003
workbook. I just need to assign some code to this button so that when
clicked, it will simply enter text into a cell in another worksheet in
the same workbook.

Sounds very easy to me, but I've not been able to figure it out yet,
or see any examples.

Can someone help me out please?

Thanks a lot.

Gary.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Command button code

On 16 May, 13:11, "Norman Jones"
wrote:
Hi Gary,

Try something like:

'=============
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
End Sub
'<<=============

---
Regards,
Norman

"Gary" wrote in message

oups.com...



Hi all,


I have created a command button on a worksheet in an Excel 2003
workbook. I just need to assign some code to this button so that when
clicked, it will simply enter text into a cell in another worksheet in
the same workbook.


Sounds very easy to me, but I've not been able to figure it out yet,
or see any examples.


Can someone help me out please?


Thanks a lot.


Gary.- Hide quoted text -


- Show quoted text -


That's great. Thanks a lot.

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

Thanks again.

  #4   Report Post  
Posted to microsoft.public.excel.programming
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Command button code

On 16 May, 13:11, "Norman Jones"
wrote:
Hi Gary,

Try something like:

'=============
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
End Sub
'<<=============

---
Regards,
Norman

"Gary" wrote in message

oups.com...



Hi all,


I have created a command button on a worksheet in an Excel 2003
workbook. I just need to assign some code to this button so that when
clicked, it will simply enter text into a cell in another worksheet in
the same workbook.


Sounds very easy to me, but I've not been able to figure it out yet,
or see any examples.


Can someone help me out please?


Thanks a lot.


Gary.- Hide quoted text -


- Show quoted text -


Thanks very much for that. I also need the same button to add a new
row into the worksheet it is located. Can you please help me with
that?

Thanks again.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Command button code

Hi Gary,

To insert the row(s) in the active sheet, change:

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


to

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

Change the location for the insertion and the number of
rows to be inserted to accord with your requirements.



---
Regards,
Norman


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Command button code

Hi Gary,

'-----------------
I also need the same button to add a new row into the
worksheet it is located. Can you please help me with
that?
'-----------------

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

Me.Range("A10").EntireRow.Insert
End Sub
'<<=============

Change the location A10 to suit.

---
Regards,
Norman


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
command button code dummy Excel Discussion (Misc queries) 2 December 1st 09 02:57 PM
Command button code packwolf94 Excel Programming 3 April 26th 07 07:54 AM
Command button code taps54 Excel Programming 3 September 21st 06 01:16 PM
VBA code behind command button [email protected] Excel Worksheet Functions 1 March 22nd 06 08:13 PM
Command Button VBA code Dave Peterson Excel Discussion (Misc queries) 2 January 25th 05 11:28 PM


All times are GMT +1. The time now is 03:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"