There is actually two questions in this post. Thank you in advance.
My first problem is that I cannot seem to get Excel to choose the Excel workbook that is named "(DATES)-Usage", where (DATES) changes each day.
Second problem is that the .Replace
Object is giving me and Run-Time error '438': Object doesn't support this property method
. Could someone please take a look and tell me where I am making my mistakes. Thank you again!
Sub UsersBySource_Update()
' Create variables
Dim ws As Worksheet
Dim wb As Workbook
Dim unspecified As String
Dim organic As String
Dim TheString As String, Cohort As Date
' Ask user for cohort date and return an error if invalid date is entered
TheString = Application.InputBox("Please Specify The Cohort:")
If IsDate(TheString) Then
Cohort = DateValue(TheString)
Else
MsgBox ("Invalid Date")
End If
' Set variables
unspecified = "[Unspecified]"
organic = "Organic"
' Activate the workbook
For Each wb In Workbooks
If wb.Name Like "*-Usage" Then
wb.Activate
End If
Next
' Find and Replace the unspecified and organic variables in the workbook
ActiveSheet.Replace What:=unspecified, Replacement:=organic, LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
' Add Columns and Row to fix formatting to continue
Columns("B:E").Insert shift:=xlToRight
Range("B2").EntireRow.Insert
' Copy and Paste initial date range to start program
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
End Sub