Select Active Workbook with Userform Code

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
Thanks for taking a look at my post.

I have a userform with a command button having the following code.
Im unsure what code to add to have it work on the active sheet. Thanks again



Code:
Private Sub CommandButton1_Click()
Range("F1") = TextBox1.Text
Range("H1") = TextBox2.Text
Range("N1") = TextBox3.Text
Range("M2") = TextBox4.Text
Range("AA1") = TextBox5.Text
Range("AA2") = TextBox6.Text
Range("AC2") = TextBox7.Text
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
That should work on the active sheet, are you saying it doesn't?
 
Upvote 0
I do have 1 problem. I keep having an error at the end with line. I Think I have it in there wrong.

Code:
Private Sub CommandButton1_Click()


With ActiveSheet
.Unprotect Password:=""




Range("F1") = TextBox1.Text
Range("H1") = TextBox2.Text
Range("N1") = TextBox3.Text
Range("M2") = TextBox4.Text
Range("AA1") = TextBox5.Text
Range("AA2") = TextBox6.Text
Range("AC2") = TextBox7.Text


With ActiveSheet
.Protect Password:=""
End With


End Sub
 
Upvote 0
You have an extra with statement that you don't need
Code:
Private Sub CommandButton1_Click()


With ActiveSheet
   .Unprotect Password:=""
   .Range("F1") = TextBox1.Text
   .Range("H1") = textbox2.Text
   .Range("N1") = textbox3.Text
   .Range("M2") = TextBox4.Text
   .Range("AA1") = TextBox5.Text
   .Range("AA2") = TextBox6.Text
   .Range("AC2") = TextBox7.Text
   
   .Protect Password:=""
End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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