Input cell info into sheet whose tab name matches same (partial) tab date

CastingDirector

New Member
Joined
Jun 10, 2014
Messages
46
Hello,
I am holding out hope that you can help me. My workbook has several sheets (up to 25). Many (not all) of the sheets have dates as part of their tab name(s) ie. "Schedule on DATE" & Call "Sheet for DATE". The date is formatted (MM-DD-YYYY). I would like to insert text information in cell "E5" on the sheet that corresponds to the same dated sheet. Seems remarkably easy yet I really have done my research and cannot find the right configuration. I've tried the following with no luck:

Code:
Dim nDate As Date
Dim N As String
nDate = (Format(nDate, "MM-DD-YYYY"))
     ActiveSheet.Name.value = ("*" & nDate)
        For Each Sh In Worksheets
               If Sh.Name Like "*" & nDate Then
               Sheets(Sh.Name)("E5").value = TextBox5.value
               End If
        Next Sh

My fear is that I will always be a newbee! This is going on years of trying to figure Excel out! Can you help?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Put a date in a cell and give nDate the value of that cell.
Example"
Code:
Dim nDate As Date, Sh[COLOR=#FF0000] As Worksheet[/COLOR]
[COLOR=#DAA520]nDate = Sheet1.Range("A1").Value[/COLOR]
Dim N As String
nDate = (Format(nDate, "mm-dd-yyyy"))
     ActiveSheet.Name.value = ("*" & nDate)
        For Each Sh In Worksheets
               If Sh.Name Like "*" & nDate Then
              [COLOR=#FF0000] Sh[/COLOR].Range("E5").value = TextBox5.value [COLOR=#008000]'Declare sh as worksheet and use it as sheet object[/COLOR]
               End If
        Next Sh
 
Upvote 0
Thanks JLGWhiz. This is amazing help! It does code out "424" Object variable so I guess I am still mission something. I am not sure what "use it as sheet object" really means...thoughts?

Code:
nDate = ActiveSheet.Range("A8").value
nDate = (Format(nDate, "mm-dd-yyyy"))
    ActiveSheet.Name.value = ("*" & nDate)
        For Each Sh In Worksheets
               If Sh.Name Like "*" & nDate Then
               Sh.Range("E5").value = ActiveSheet("E5").value  'Declare sh as worksheet and use it as sheet object
               End If
        Next Sh
 
Upvote 0
I am not sure what "use it as sheet object" really means...thoughts?
When you declare sh as a worksheet in your declarations and then use it in the For Each statement, it has the same effect as a Set statement. So if the first qualified sheet in the workbook is named data the variable sh would be equivalent to Sheets("data") as if you had used
Code:
Set sh = Sheets("data")
The sh variable holds the Sheets("data") string as a range object so you don't have to use the Sheets(sh.Name) syntax. The sh variable automatically picks up the next sheet object info on each iteration of the loop.

Change this
Code:
ActiveSheet.Name.value = ("*" & nDate)
To this
Code:
ActiveSheet.Name = ("*" & nDate)
you can't use value on a Name property. But I don't know what you are attempting with that line anyhow.
 
Last edited:
Upvote 0
When you declare sh as a worksheet in your declarations and then use it in the For Each statement, it has the same effect as a Set statement. So if the first qualified sheet in the workbook is named data the variable sh would be equivalent to Sheets("data") as if you had used
Code:
Set sh = Sheets("data")
The sh variable holds the Sheets("data") string as a range object so you don't have to use the Sheets(sh.Name) syntax. The sh variable automatically picks up the next sheet object info on each iteration of the loop.

Change this
Code:
ActiveSheet.Name.value = ("*" & nDate)
To this
Code:
ActiveSheet.Name = ("*" & nDate)
you can't use value on a Name property. But I don't know what you are attempting with that line anyhow.


This was so helpful and kind of you. You have my sincere thanks.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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