Forum Discussion
VBA
The code provided contains several errors that need to be corrected.
Here are the identified errors and the corresponding corrections:
- Error: The variables wbSrc and wsSrc are not declared.
Correction: Add the declarations for wbSrc and wsSrc before using them in the code. For example:
Vba code
Dim wbSrc As Workbook
Dim wsSrc As Worksheet- Error: The variable names wbDst and NewSht are used interchangeably, but they refer to different objects.
Correction: Replace all instances of NewSht with wbDst.Worksheets(1) to refer to the correct worksheet object.
- Error: The loop counter variable i is not declared.
Correction: Add the declaration for the loop counter i before using it in the code. For example:
vba code
Dim i As Integer- Error: The variables wbDst, wbSrc, wsSrc, ActBook, and ActSht are not being assigned properly.
Correction: Update the assignments for these variables to reference the correct workbook and worksheet objects. For example:
vba code
Set wbDst = Workbooks.Add(xlWBATWorksheet)
Set wbsrc=Workbooks.Open(Filename:=MyFolder & "\" & StrFilename, UpdateLinks:=0, ReadOnly:=False)
Set wssrc=wbSrc.Worksheets(1)- Error: The variables wbSrc and wssrc are used instead of wbSrc and wsSrc.
Correction: Update the variable names to use the correct casing. Replace all instances of wssrc with wsSrc.
After making these corrections, the code should run without errors. The text and steps were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.