0

I get an error using Workbooks("fastener_calculator_simplified_v3 test (1) BACKUP BACKUP MACRO.xlsm").Sheets("Random Vibration, X").Range(Cells(ex-i+1, "A"), Cells(ex-1, "A")) = nme in a bigger code, but the line works fine if I use it alone in a seperate sub. The error says Application-defined or object defined error 1004

Here is a part of the bigger code:

nme = Mid(wb.name, InStrRev(wb.name, "(") + 1, InStrRev(wb.name, ")") - InStrRev(wb.name, "(") - 1)
If nme2 = "X" Then
Do While wb.Sheets(1).Cells(5, i) <> ""
wb.Sheets(1).Range(Cells(5, i), Cells(9, i)).Copy
Workbooks("fastener_calculator_simplified_v3 test (1) BACKUP BACKUP MACRO.xlsm").Sheets("Random Vibration, X").Cells(ex, "B").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
ex = ex + 1
i = i + 1
Loop
Workbooks("fastener_calculator_simplified_v3 test (1) BACKUP BACKUP MACRO.xlsm").Sheets("Random Vibration, X").Cells.Replace What:="% ", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Workbooks("fastener_calculator_simplified_v3 test (1) BACKUP BACKUP MACRO.xlsm").Sheets("Random Vibration, X").Range(Cells(ex - i + 1, "A"), Cells(ex - 1, "A")) = nme
dominykas
  • 13
  • 4
  • 1
    Not tested but `Cells(ex - i + 1, "A")` should be referenced to the proper workbook. If you don't punt anything, it's referencing the active one. Also, what is the value of `nme` when it raises the error? – Foxfire And Burns And Burns May 05 '22 at 09:34
  • Yes, I needed to qualify it, at first I just put sheet reference, but it only worked when I added workbook reference as well. Thanks! – dominykas May 05 '22 at 09:39

0 Answers0