Application-defined or object-defined error when assigning a new value to a cell

Viewed 22

As the title says, I am trying to assign a value from a variable to a certain cell and it is giving me the Application-defined or object-oriented error.

Below is the code and the last line modified_ABC.Cells(RowNumber, ColumnNumber).Value = CustomUserValue is where the error occurs.

If anyone can help me figure this out, I really appreciate it.

Sub sub1()

Dim xlwb As Workbook
Dim xlwks As Worksheet
Dim MasterWb As Workbook
Dim InterfaceWire As Worksheet
Dim original_wb As Workbook
Dim modified_wb As Workbook

Dim original_filename As String
Dim copy_filename As String

original_filename = Dir(InputPath)
copy_filename = Dir(InputPath_copy)

Set MasterWb = Workbooks("Coordinator.xlsm")
Set InterfaceWire = MasterWb.Sheets(1)
Set modified_wb = Workbooks(copy_filename)
Set original_wb = Workbooks(original_filename)

Dim SheetName As String
Dim RowName As String
Dim ColumnName As String
Dim CustomUserValue As Variant
Dim Additionalid As Variant
Dim ExistingValue As Variant
Dim ExistingValue_2 As Variant

SheetName = InterfaceWire.Range("D15").Value
RowName = InterfaceWire.Range("G15").Value
ColumnName = InterfaceWire.Range("J15").Value
CustomUserValue = InterfaceWire.Range("P15").Value
Additinalid = InterfaceWire.Range("M15").Value

Set xlwks = MasterWb.Sheets("Coordinates")

lastrow = xlwks.Cells(xlwks.Rows.Count, 1).End(xlUp).Row

i = 1

Do Until i > lastrow
    
    Dim coordinate_shtname As String
    Dim cooridnate_RowName As String
    Dim coordinate_clmnName As String
    
    Dim ABCSheetName As String

    
coordinate_shtname = MasterWb.Sheets("Coordinates").Cells(i, "A").Value

    
    If SheetName = MasterWb.Sheets("Coordinates").Cells(i + 1, "A").Value And RowName = MasterWb.Sheets("Coordinates").Cells(i + 1, "C").Value And ColumnName = MasterWb.Sheets("Coordinates").Cells(i + 1, "D").Value Then
    
        'Dim RowNumber As Double
        RowNumber = xlwks.Cells(i + 1, "E").Value
        ColumnNumber = xlwks.Cells(i + 1, "F").Value
        ABCSheetName = xlwks.Cells(i + 1, "B").Value
        Exit Do
    End If
    
    i = i + 1

 
Loop


Dim original_ABC As Worksheet
Set original_ABC = original_wb.Sheets(ABCSheetName)


ExistingValue = original_ABC.Cells(RowNumber, ColumnNumber).Value
ExistingValue_2 = original_ABC.Cells(RowNumber, ColumnNumber).Value

Dim modified_ABC As Worksheet
Set modified_ABC = modified_wb.Sheets(ABCSheetName)

modified_ABC.Cells(RowNumber, ColumnNumber).Value = CustomUserValue

I tried different ways to write the last line (for example, not using set and dim for the worksheet variable)

0 Answers
Related