Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Pass a cell in sheet to macro or command button

Is there a way to pass a cell in a sheet to a macro or command button?
I have a spreadsheet that I created for a group of users which
ultimately creates a csv file to be uploaded to another system. The
users input various information and then the spreadsheet performs
calculations. I do not want to create the final csv file unless certain
conditions are met within the calculations. I have code to create the
final csv file (from a command button); however, I can't figure out how
to limit the creation of the file based on the parameters from the
spreadsheet. Any help would be appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Pass a cell in sheet to macro or command button

If you wish to prevent a commandbutton from being active, you can use

CommandButton1.Enabled = False

So in your sheet, you might add use a change event or the calculate event to
test if the cell has a specific value which will enable the command button.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") = "123" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub

Alternatively include the test in the macro that is initiated by the user
pressing the command button, this of course may not do anything and could
confuse the user....

'your sub
If Range("A1") < "123" then Exit Sub
' your code





--
Cheers
Nigel



"Connie" wrote in message
ups.com...
Is there a way to pass a cell in a sheet to a macro or command button?
I have a spreadsheet that I created for a group of users which
ultimately creates a csv file to be uploaded to another system. The
users input various information and then the spreadsheet performs
calculations. I do not want to create the final csv file unless certain
conditions are met within the calculations. I have code to create the
final csv file (from a command button); however, I can't figure out how
to limit the creation of the file based on the parameters from the
spreadsheet. Any help would be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Pass a cell in sheet to macro or command button

Nigel: Both options worked beautifully. I prefer the second option as
this way I can display a message box to let the user know why they
can't proceed. Here's the code I used:

Private Sub Test_Errors_Click()
If Range("TestErrors") = False Then
MsgBox "You have unresolved ERRORS. Please View the Error
Report and resolve all errors before proceeding."
Exit Sub
Else
My Code
End If
End Sub

Thanks so much for your help! I really appreciate it.

Nigel wrote:
If you wish to prevent a commandbutton from being active, you can use

CommandButton1.Enabled = False

So in your sheet, you might add use a change event or the calculate event to
test if the cell has a specific value which will enable the command button.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") = "123" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub

Alternatively include the test in the macro that is initiated by the user
pressing the command button, this of course may not do anything and could
confuse the user....

'your sub
If Range("A1") < "123" then Exit Sub
' your code





--
Cheers
Nigel



"Connie" wrote in message
ups.com...
Is there a way to pass a cell in a sheet to a macro or command button?
I have a spreadsheet that I created for a group of users which
ultimately creates a csv file to be uploaded to another system. The
users input various information and then the spreadsheet performs
calculations. I do not want to create the final csv file unless certain
conditions are met within the calculations. I have code to create the
final csv file (from a command button); however, I can't figure out how
to limit the creation of the file based on the parameters from the
spreadsheet. Any help would be appreciated.


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
Use macro(command button) paste special in 2nd sheet deen Excel Worksheet Functions 5 February 25th 08 01:04 PM
Calling command button from another sheet Ian[_17_] Excel Programming 4 April 13th 06 07:41 PM
Command Button Macro SheetNew Workbook Norman Jones Excel Programming 0 November 30th 05 07:33 AM
How do I create a command button to jump from sheet to sheet in a. Darlenew Excel Worksheet Functions 3 March 22nd 05 10:36 PM
Running a Command Button from a different sheet Lester Lee Excel Programming 5 July 14th 04 05:15 PM


All times are GMT +1. The time now is 03:13 AM.

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"