이 게시물에는 실제로 두 가지 질문이 있습니다. 미리 감사드립니다.통합 문서 선택 및 찾기/바꾸기
첫 번째 문제는 Excel에서 "(날짜) -Usage"라는 Excel 통합 문서를 선택할 수 없다는 것입니다. 여기서 (날짜)는 매일 변경됩니다.
두 번째 문제는 .Replace
개체가 나를주고 Run-Time error '438': Object doesn't support this property method
입니다. 누군가 제발 저를보고 실수를 저에게 해줄 수 있습니까? 다시 감사합니다!
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
'Replace' 메서드는 워크 시트가 아닌 범위에서 작동한다고 생각합니다. – Brian
이제 답을 얻었으니 (** 예를 들어!), ** ** 읽고 쓰고, 구현하는 것이 좋습니다. ('.Select' 사용을 피하십시오.) (http://stackoverflow.com/questions/10714251/how-to- 엑셀 - 베타 - 매크로를 사용하지 마십시오). 코드가 더 강력 해지고 오류가 발생하지 않게되며 데이터로 직접 작업하는 방법을 알려줍니다. 이렇게하면 매크로가 더 빠르게 실행될 수 있습니다. – BruceWayne