Call Sub Routine

cpgscoord

New Member
Joined
Nov 13, 2008
Messages
3
I have a userform with a commandbutton that I would like to have call the same procedure whenever the commandbutton is pressed. I am using Excel 2003.

The code for the command button is:

Private Sub CommandButton16_Click()
Sheets("Info").Select
Call Fill
UserForm1.Hide
Application.Visible = True
End Sub

'and the module code is:

Sub Fill()
Range("C1").Select
Range("C1") = SalesRegion
Range("C3") = GroupID
Range("C4") = GroupName
Range("C5") = FirstName
End Sub

When I currenty hit the command button I do not get any error messages, and my sheet (Info) is selected, my cell (C1) is selected, my userform hides, and my application is visible. It's as if the Sub Fill stops after Range("C1").Select. I've checked the spelling of my texbox names (SalesRegion, GroupID, GroupName) and they all match...in fact, the following code works when I place it in the Commandbutton:

Private Sub CommandButton16_Click()
Sheets("Info").Select
Range("C1").Select
Range("C1") = SalesRegion
Range("C3") = GroupID
Range("C4") = GroupName
Range("C5") = FirstName
UserForm1.Hide
Application.Visible = True
End Sub

but that dosen't help me, as I want the same routine to fire anytime I hit a handfull of commandbuttons.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Wellcome tothe board :)

First of all you do not need to select Range C1 for anything.
Secondly, try writing the values to the cells by using proper qualifiers

Code:
Range("C1")[COLOR=Red].value[/COLOR] = [COLOR=Red]Userform1.[/COLOR]SalesRegion[COLOR=Red].value[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,825
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top