Save my internship

DNiersbach

New Member
Joined
Jul 15, 2015
Messages
27
Hey guys I'm new here and this is my first post.

I'm trying to write a macro that will enter data into a worksheet based on the values entered in the form. I've created the user form but the coding is giving me issues.

I'm trying to write a function that will activate the sheet matching the first two inputs before entering the rest of the data in the sheet.

For example,

B1=7/1/15 and C1=Name

How do I get the macro to activate sheet "Name 07-15" my matching the above cells?

Thank you!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try

Code:
Sub DNiersbachtesting()
Dim ws As Worksheet, sname As String
sname = Range("C1") & " " & Format(Range("B1"), "mm-yy")
Set ws = Sheets(sname)
Debug.Print ws.Name
End Sub
 
Upvote 0
Welcome to the Board!

Note that you don't need to activate the sheet in order to write to it. Just reference it as in the example above.
 
Upvote 0
I entered that code to a button and it didn't giver an error or jump to a page.

UPDATE: I created a cell on the sheet equal to the name of the sheet. So cell D1 and sheet name are equal to John 07-15. This may make it easier to locate?
 
Upvote 0
If you really want to jump to the page, you would change

Code:
Debug.print ws.name

to

Code:
ws.activate

also, I was presuming 07 is the month not the day. Is that correct?
 
Upvote 0
Yes, that would be the month. I ran it and got a run-time error 1004.

EDIT: I'm really new to macros. Just started on Wednesday trying to learn.

Code:
Sub DNiersbachtesting()
Dim ws As Worksheet, sname As String
sname = Range("F") & " " & Format(Range("B1"), "mm-yy")
Set ws = Sheets(sname)
ws.Activate
End Sub
 
Last edited:
Upvote 0
You need to give a full range address:

Range("F")

Like Range("F5")

And it's not necessary, but it's good to add .Value:

Range("F5").Value
 
Upvote 0
Subscript out of range, Run-time error 9.

Code:
Private Sub CommandButton1_Click()

Dim ws As Worksheet, sname As String
sname = Range("F1").Value & " " & Format(Range("B1").Value, "mm-yy")
Set ws = Sheets(sname)
Debug.Print ws.Name


End Sub
 
Upvote 0
The sname string and worksheet name need to be identical.

I'd debug.print sname and see what you get.
 
Upvote 0
Not positive what you mean, sorry. My master sheet is named MASTER, but each employee has their own sheet I am trying to have the forum enter data into correctly.

Code:
Private Sub CommandButton1_Click()

Dim ws As Worksheet, sname As String
sname = Range("F1").Value & " " & Format(Range("B1").Value, "mm-yy")
Set ws = Sheets(MASTER)
Debug.Print sname


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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