i try to create button to add data with looping on last row, but i got error with code "object variable or with block variable not set"
here is my code
Sub Add_Click2()
Application.ScreenUpdating = False
Dim emptyRow1 As Long
Dim Celltujuan2 As Range
Set Menu = Sheets("Interface")
Set Db2 = Sheets("Database CMMS")
'DB Power
Db2.Activate
RCNumberCMMS = Menu.Range("D20").Value
Set Celltujuan2 = Db2.Range("A:A").Find(What:=RCNumberCMMS)
If RCNumberCMMS = "" Then
MsgBox ("Silakan isi RC Number terlebih Dahulu!")
Exit Sub
End If
Celltujuan2 = Db2.Range("A99999").End(xlUp).Row + 1
'Info
For i = 25 To 35
Cells(Celltujuan2, Menu.Range("E" & i).Value) = Menu.Range("D" & i).Value
Next i
'DOP & Approval
For i = 25 To 34
Cells(Celltujuan2, Menu.Range("I" & i).Value) = Menu.Range("H" & i).Value
Next i
'Install & Material Eks
For i = 25 To 33
Cells(Celltujuan2, Menu.Range("M" & i).Value) = Menu.Range("L" & i).Value
Next i
'Write Off
For i = 25 To 26
Cells(Celltujuan2, Menu.Range("Q" & i).Value) = Menu.Range("P" & i).Value
Next i
MsgBox ("Data Telah Terupdate")
Menu.Activate
Menu.Range("D20").Select
End Sub
i do the same code for other sheet and running well, i create this code in the same workbook but in diffren module, is that the problem ?
Celltujuan2 = Db2.Range("A99999").End(xlUp).Row + 1needs to beset Celltujuan2 = Db2.Range("A99999").End(xlUp).Row + 1Db2.Range("A99999").End(xlUp).Row + 1returns a number, which isn't compatible with a range variable.Set Celltujuan2 = Db2.Range("A:A").Find(What:=RCNumberCMMS)Then you try to overwrite the same variableCelltujuan2 = Db2.Range("A99999").End(xlUp).Row + 1It is very unclear what you are trying to do here.If RCNumberCMMS = "" Thenhas nothing to do withIf Celltujuan2 Is Nothing Thenthat doesn't need to be replaced, that is a completly independent test. Just add the test forIf Celltujuan2 Is Nothing Then.