Forum Discussion
Pop up error: run time error 438 object doesn't support this property or method
- Aug 07, 2022
- hrh_dashAug 15, 2022Iron Contributor
HansVogelaar , i have a query regarding on this thread as it is somehow similar.
I am trying to create this macro code to find if DC2 is found in Sheets("TCA"), if yes, it would copy and paste the batch id into my source worksheet ("Count").
So when i execute the code the first time, it populates "DC2" in my source worksheet ("Count"). However, when i execute the code the 2nd time, it populates the batch id into my source worksheet.
Seems like the code needs to run twice to capture the batch id in Sheets("TCA") which is quite weird. Not sure what is wrong, i don't have any issues with the rest as the code is the same just amending the variables.
the code as follows:
Dim ws As Worksheet Dim ws1 As Worksheet Dim DestDC1 As Range Dim DestDC2 As Range Dim Destmisc As Range Set ws = ThisWorkbook.Sheets("Count") Set ws1 = ThisWorkbook.Sheets("TCA") Set Destmisc = ws1.Cells.Find(What:="MISC", After:=ActiveCell, LookIn:=xlValues _ , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False) Set DestDC1 = ws1.Cells.Find(What:="DC1", After:=ActiveCell, LookIn:=xlValues _ , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False) Set DestDC2 = ws1.Cells.Find(What:="DC2", After:=ActiveCell, LookIn:=xlValues _ , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False) If ws.Range("B3").Value = 0 Then ws.Range("B5").Value = "" Else Destmisc.Copy ws.Range("B5").PasteSpecial Paste:=xlPasteValues End If If ws.Range("C3").Value = 0 Then ws.Range("C5").Value = "" Else DestDC1.Copy ws.Range("C5").PasteSpecial Paste:=xlPasteValues End If If ws.Range("D3").Value = 0 Then ws.Range("D5").Value = "" Else DestDC2.Copy ws.Range("D5").PasteSpecial Paste:=xlPasteValues End If
1st run
2nd run
- HansVogelaarAug 15, 2022MVP
I'd have to see a copy of the workbook.
- hrh_dashAug 16, 2022Iron Contributor
HansVogelaar , excel workbook attached. The code is placed under Worksheet "Count". It would be under Sub counter().
Thank you and appreciate the assistance.