I have tried to debug the code where the error has occured by introducing a msgbox statement just before that. The result was the sheet name (1029, etc.) available in the workbook. Screenshot of sheets in the workbook attached for your reference. Kindly suggest a probable solution.That error just means that the sheet name is wrong (i.e. it doesn't exist in that workbook).
Set wsdest1 = wb1.sheets("" & shname1)
lrow2
on a different sheet to the one whose cells you are reading.What is the significance of the "etc" ? What is the name in the "last" message box before it errors out ?The result was the sheet name (1029, etc.)
Dim wscopy1 As Worksheet, wsdest1 As Worksheet, wsinterim1 As Worksheet
Dim a As Long, lrow2 As Long, lrow3 As Long
Hi. I tried the quote mentioned. But this doesn't workThe code should work assuming the correct workbook is active at the time because you have explicitly declared the variable as a string, but you could try adding quotes like this:
Code:Set wsdest1 = wb1.sheets("" & shname1)
I'm not sure why you are calculatinglrow2
on a different sheet to the one whose cells you are reading.
Set wsdest1 = wb1.sheets("" & shname1)
The msg box before the error pops out is attached. Declarations as suggested also doesn't help.What is the significance of the "etc" ? What is the name in the "last" message box before it errors out ?
Also a lot of your declarations don't work and will result in the variables being variant
eg Your worksheet and long dim lines should look like this:
VBA Code:Dim wscopy1 As Worksheet, wsdest1 As Worksheet, wsinterim1 As Worksheet Dim a As Long, lrow2 As Long, lrow3 As Long
I found that bug and it is already corrected. Still the error persists.You calculate lrow2 based on the data in Sheet20 (the Service sheet) but then when you use it in the loop, you're looking at the SCM sheet, which seems odd.
If you are still getting the error, then the sheet name does not exist in the specified workbook. There is no other cause.