尝试向现有代码插入新的格式设置指令时接收"Compile Error: Next without For"



我已经对现有代码进行了修改(我在下面插入了双星号(。没有我的添加,现有的代码可以很好地工作,我不知道为什么一旦包括了额外的单元格边界格式,我就会收到上面的提示,";编译错误:下一个没有For;。我收到此错误消息的代码行也是双星号。我查阅了现有的线索,但似乎没有一条建议适用。请有人帮忙好吗?谢谢

`For Each WS In Worksheets
'This code will delete the debt financing in the Property Summary tab
With Worksheets("Property Summary").Activate
'Range might need to be updated if it has moved around due to AE 
version updates.
Range("E27:H36").Delete
Range("E27:H36").Select
Selection.ClearContents
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With

**Range("E26:H26").Select
Selection.Border(xlEdgeLeft).LineStyle = xlNone
Selection.Border(xlEdgeRight).LineStyle = xlNone
With Selection.Border(xlEdgeTop)
.Pattern = xlContinuous
.TintAndShade = 5
.Weight = xlThin
End With**

'This code will clean up the Cash Flow Report tab
With Worksheets("Cash Flow").Activate

'Range might need to be updated if it has moved around due to AE version updates
Range("A2").Select

Cells.Replace What:=" (Amounts in EUR)", Replacement:="", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Cells.Replace What:=" (Amounts in PLN)", Replacement:="", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Cells.Replace What:=" (Amounts in USD)", Replacement:="", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

NomProperty = Range("A2").Value
'Blue
Range("B8:L8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With

'Clean Up

'This will unmerge the first 4 rows (A1:M4) and delete columns M:Z
Range("A1:M4").Select
Selection.UnMerge
Columns("L:Z").Select
Selection.Delete Shift:=xlToLeft

'This will delete unwanted rows and minimize rows
For i = 9 To 100

If Cells(i, 1).Value = "" Or Cells(i, 1).Value = " " Or Cells(i, 1).Value = "  " Or 
Cells(i, 1).Value = "   " Or Cells(i, 1).Value = "    " Then
Rows(i).RowHeight = 3
GoTo Following
End If

If Cells(i, 1).Value = "  Scheduled Base Rent" Then GoTo Following
If Cells(i, 1).Value = "  CPI Increases" Then GoTo Following
If Cells(i, 1).Value = "  Free CPI Increases" Then GoTo Following
If Cells(i, 1).Value = "Total Rental Revenue" Then GoTo Following
If Cells(i, 1).Value = "Total Other Revenue" Then GoTo Following
If Cells(i, 1).Value = "Potential Gross Revenue" Then GoTo Following
If Cells(i, 1).Value = "Total Vacancy & Credit Loss" Then GoTo Following
If Cells(i, 1).Value = "Effective Gross Revenue" Then GoTo Following
If Cells(i, 1).Value = "Net Operating Income" Then GoTo Following
If Cells(i, 1).Value = "  Total Capital Expenditures" Then GoTo Following
If Cells(i, 1).Value = "Total Leasing & Capital Costs" Then GoTo Following
If Cells(i, 1).Value = "Cash Flow Before Debt Service" Then GoTo Following
If Cells(i, 1).Value = "Cash Flow Available for Distribution" Then GoTo Following
If Cells(i, 1).Value = "Total Other Tenant Revenue" Then GoTo Following
If Cells(i, 1).Value = "Total Tenant Revenue" Then GoTo Following
If Cells(i, 1).Value = "Total Operating Expenses" Then GoTo Following
If Cells(i, 1).Value = "Property Resale" Then GoTo Following
If Cells(i, 1).Value = "Total Cash Flow" Then GoTo Following

Rows(i).Delete Shift:=xlUp
i = i - 1
Rows(9).RowHeight = 12.75




Following:
Next
DATABASE_LOC = "C:Users32948DesktopCockpitCockpit"
If IsFileOpen(DATABASE_LOC & "Cashflow Appendix.xlsx") Then
Windows("Cashflow Appendix.xlsx").Activate
Else
Set WbDatabase = Workbooks.Open(DATABASE_LOC & "Cashflow Appendix.xlsx")
End If
WB_Appendix_Name = "Cashflow Appendix.xlsx"
Windows(WB_Appendix_Name).Activate
Columns("A:Z").Select
Selection.Delete Shift:=xlUp

Cells.Select
Selection.Copy
Windows(WB_Appendix_Name).Activate
Cells.Select
ActiveSheet.Paste

ActiveWorkbook.Save
ActiveWorkbook.Close
Set WbDatabase = Nothing
End With


**Next WS**

ActiveWorkbook.Save
ActiveWorkbook.Close True
Application.StatusBar = MyFile & " closed."

'read next filename
MyFile = Dir()
Loop` 

With Worksheets("Property Summary").Activate

Activate方法不返回任何可以在With块中使用的内容

? typename(activesheet.activate) '>>Boolean

并且您没有使用来自外循环的WS

插入的代码是从哪里来的?我不能只在一个示例宏中运行插入,但这运行了

Sub topborder()
Range("E26:H26").Select
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
End Sub

最新更新