A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Checkbox Macro



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2008, 12:33 AM posted to microsoft.public.excel.misc
Ben in CA[_2_]
external usenet poster
 
Posts: 20
Default Checkbox Macro

Hello,

Here's a question that shows my ignorance when it comes to Excel macros.

How can I copy the data contained in one cell to the next cell on the same
row (without referencing the cell names in the macro) by pressing a checkbox?

How about leaving an empty column in between - copying from cell S2 to U2,
for instance?

Thanks in advance for anyone who has some ideas!
  #2  
Old December 9th, 2008, 01:42 AM posted to microsoft.public.excel.misc
Gord Dibben
external usenet poster
 
Posts: 20,252
Default Checkbox Macro

You will need event code behind the sheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "S1:S10" 'adjust to suit

Application.EnableEvents = False
On Error Resume Next
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Target.Offset(0, 2).Value = Target.Value
End If
On Error GoTo 0
Application.EnableEvents = True
End Sub

Right-click on the sheet tab and "View Code". Copy/paste the above code
into that module.

Edit the range to suit. Alt + q to return to the Excel window.

Click on any cell in the S1:S10 range and the value will then be copied to
column U


Gord Dibben MS Excel MVP

On Mon, 8 Dec 2008 15:33:01 -0800, Ben in CA
wrote:

Hello,

Here's a question that shows my ignorance when it comes to Excel macros.

How can I copy the data contained in one cell to the next cell on the same
row (without referencing the cell names in the macro) by pressing a checkbox?

How about leaving an empty column in between - copying from cell S2 to U2,
for instance?

Thanks in advance for anyone who has some ideas!


  #3  
Old December 9th, 2008, 05:24 PM posted to microsoft.public.excel.misc
Ben in CA[_2_]
external usenet poster
 
Posts: 20
Default Checkbox Macro

Thank you very much for your reply.

I might be able to use that the way it is, but is there a way I can have it
setup so that it only copies when I press a button or a checkbox?

Ben


"Gord Dibben" wrote:

You will need event code behind the sheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "S1:S10" 'adjust to suit

Application.EnableEvents = False
On Error Resume Next
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Target.Offset(0, 2).Value = Target.Value
End If
On Error GoTo 0
Application.EnableEvents = True
End Sub

Right-click on the sheet tab and "View Code". Copy/paste the above code
into that module.

Edit the range to suit. Alt + q to return to the Excel window.

Click on any cell in the S1:S10 range and the value will then be copied to
column U


Gord Dibben MS Excel MVP

On Mon, 8 Dec 2008 15:33:01 -0800, Ben in CA
wrote:

Hello,

Here's a question that shows my ignorance when it comes to Excel macros.

How can I copy the data contained in one cell to the next cell on the same
row (without referencing the cell names in the macro) by pressing a checkbox?

How about leaving an empty column in between - copying from cell S2 to U2,
for instance?

Thanks in advance for anyone who has some ideas!



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:37 PM.


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