0

My excel is being corrupted. When I open excel the following message appears:

"We found a problem with some content in "". Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes"

And when I click "yes" opens excel with the "input4" tab misconfigured

I think it may be something related to the macros I added below.

I can't figure out where the problem is, can someone help me please?

Sub gera_quadro_inp4()

Dim n As Integer
Dim u As Integer
Dim LastR As Integer
Dim Cart As String

With Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("B7:B100").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="mar/2008,jun/2008,set/2008,dez/2008,mar/2009,jun/2009,set/2009,dez/2009,mar/2010,jun/2010,set/2010,dez/2010,mar/2011,jun/2011,set/2011,dez/2011,mar/2012,jun/2012,set/2012,dez/2012,mar/2013,jun/2013,set/2013,dez/2013,mar/2014,jun/2014,set/2014,dez/2014,mar/2015,jun/2015,set/2015,dez/2015,mar/2016,jun/2016,set/2016,dez/2016,mar/2017,jun/2017,set/2017,dez/2017,mar/2018,jun/2018,set/2018,dez/2018,mar/2019,jun/2019,set/2019,dez/2019,mar/2020,jun/2020,set/2020,dez/2020,mar/2021,jun/2021,set/2021,dez/2021,mar/2022,jun/2022,set/2022,dez/2022,mar/2023,jun/2023,set/2023,dez/2023,mar/2024,jun/2024,set/2024," & _
"dez/2024,mar/2025,jun/2025,set/2025,dez/2025,mar/2026,jun/2026,set/2026,dez/2026,mar/2027,jun/2027,set/2027,dez/2027,mar/2028,jun/2028,set/2028,dez/2028,mar/2029,jun/2029,set/2029,dez/2029,mar/2030,jun/2030,set/2030,dez/2030,mar/2031,jun/2031,set/2031,dez/2031,mar/2032,jun/2032,set/2032,dez/2032,mar/2033,jun/2033,set/2033,dez/2033,mar/2034,jun/2034,set/2034,dez/2034,mar/2035,jun/2035,set/2035,dez/2035,mar/2036,jun/2036,set/2036,dez/2036,mar/2037,jun/2037,set/2037,dez/2037,mar/2038,jun/2038,set/2038,dez/2038,mar/2039,jun/2039,set/2039,dez/2039,mar/2040,jun/2040,set/2040,dez/2040"
End With

LastR = Workbooks("TAB AUTO.xlsm").Sheets("input1").Range("C8").End(xlDown).row

'Armazena carteiras em Cart
For Each Value In Workbooks("TAB AUTO.xlsm").Sheets("input1").Range("B8:B" & LastR)
Cart = Cart & "," & Value
Next Value

'Cria lista de opção de carteiras
With Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("C7:C100").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Cart
End With


'Cria variáveis do quadro
cen = Workbooks("TAB AUTO.xlsm").Sheets("input3").Range("F6").Value
Workbooks("TAB AUTO.xlsm").Sheets("input4").Range(Workbooks("TAB AUTO.xlsm").Sheets("input4").Cells(6, 2), Workbooks("TAB AUTO.xlsm").Sheets("input4").Cells(6, 100)).Value = ""

Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("B6").Value = "PERIODO_TRI_AJUSTE"
Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("C6").Value = "CARTEIRA"
Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("D6").Value = "VALOR_ANCL_ANT"

For u = 1 To cen
    Workbooks("TAB AUTO.xlsm").Sheets("input4").Cells(6, 4 + u).Value = "OVERRIDE_TRI_C" & u
    Workbooks("TAB AUTO.xlsm").Sheets("input4").Cells(6, 4 + cen + u).Value = "OVERRIDE_ANO_C" & u
Next u



Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Select

With Selection.Interior
       .Pattern = xlSolid
       .PatternColorIndex = xlAutomatic
       .ThemeColor = xlThemeColorDark1
       .TintAndShade = -0.149998474074526
       .PatternTintAndShade = 0
   End With
   Selection.Borders(xlDiagonalDown).LineStyle = xlNone
   Selection.Borders(xlDiagonalUp).LineStyle = xlNone
   With Selection.Borders(xlEdgeLeft)
       .LineStyle = xlContinuous
       .ColorIndex = 0
       .TintAndShade = 0
       .Weight = xlThin
   End With
   With Selection.Borders(xlEdgeTop)
       .LineStyle = xlContinuous
       .ColorIndex = 0
       .TintAndShade = 0
       .Weight = xlThin
   End With
   With Selection.Borders(xlEdgeBottom)
       .LineStyle = xlContinuous
       .ColorIndex = 0
       .TintAndShade = 0
       .Weight = xlThin
   End With
   With Selection.Borders(xlEdgeRight)
       .LineStyle = xlContinuous
       .ColorIndex = 0
       .TintAndShade = 0
       .Weight = xlThin
   End With
   With Selection.Borders(xlInsideVertical)
       .LineStyle = xlContinuous
       .ColorIndex = 0
       .TintAndShade = 0
       .Weight = xlThin
   End With
   With Selection.Borders(xlInsideHorizontal)
       .LineStyle = xlContinuous
       .ColorIndex = 0
       .TintAndShade = 0
       .Weight = xlThin
   End With
   With Selection.Font
       .Name = "Calibri"
       .Size = 11
       .Strikethrough = False
       .Superscript = False
       .Subscript = False
       .OutlineFont = False
       .Shadow = False
       .Underline = xlUnderlineStyleNone
       .ThemeColor = xlThemeColorLight1
       .TintAndShade = 0
       .ThemeFont = xlThemeFontMinor
   End With
   With Selection.Font
       .Name = "Calibri"
       .Size = 11
       .Strikethrough = False
       .Superscript = False
       .Subscript = False
       .OutlineFont = False
       .Shadow = False
       .Underline = xlUnderlineStyleNone
       .ThemeColor = xlThemeColorLight1
       .TintAndShade = 0
       .ThemeFont = xlThemeFontMinor
   End With
   Selection.Font.Bold = True

Cells.Select

Cells.EntireColumn.AutoFit
Range("A1").Select

End Sub

'Gera input4 Sub gera_input4()

Dim nework As Workbook

Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

Set nework = Workbooks.Add

nework.Sheets(1).Range("A1").PasteSpecial xlPasteValues

nework.Sheets(1).Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "mmm-yy"

Cells.Select
Cells.EntireColumn.AutoFit
nework.Sheets(1).Range("A1").Select

End Sub

  • 1
    [How to avoid using Select in Excel VBA](https://stackoverflow.com/q/10714251) – Mathieu Guindon Oct 09 '19 at 18:06
  • If you have a backup copy of the file before you added the code, open that file and add the code again and see if it corrupts. If it does, add the code little by little to find the offending issue. All that said, I suspect it's not just adding the code that is the issue, but how the code runs. In that light, follow the same pattern. – Scott Holtzman Oct 09 '19 at 18:14
  • I'm noting that the problem is in this part of the code: With Workbooks("TAB AUTO.xlsm").Sheets("input4").Range("B7:B100").Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="mar/2008,jun/2008,set/2008,dez/2008,mar/2009,jun/2009,set/2009,dez/2009,mar/2010,jun/2010,set/2010,dez/2010,mar/2011,jun/2011,set/2011,dez/2011,mar/2012,jun/2012,set/2012,dez/2012,mar/2013,jun/2013,set/2013,dez/2013 – usuario_estudo Oct 09 '19 at 19:45

0 Answers0