I'm new to excel. I have some error problem getting values from other sheets using macro vba.
This is my code in macro vba :
Sub inputDataInvestment()
If ThisWorkbook.Sheets("ACTIVITY").Range("C5").Value = "FUNDING" Then
Dim Baris, totalBaris As Long
totalBaris = ThisWorkbook.Sheets("FUNDING HISTORY").Cells.Rows.Count
Baris = ThisWorkbook.Sheets("FUNDING HISTORY").Cells(totalBaris, 2).End(xlUp).Row + 1
ThisWorkbook.Sheets("FUNDING HISTORY").Range("A" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E8").Value
ThisWorkbook.Sheets("FUNDING HISTORY").Range("B" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E12").Value
ThisWorkbook.Sheets("FUNDING HISTORY").Range("C" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E13").Value
MsgBox "Funding sudah masuk database"
ThisWorkbook.Sheets("ACTIVITY").Range("E8").Value = ""
ThisWorkbook.Sheets("ACTIVITY").Range("E12").Value = ""
ElseIf ThisWorkbook.Sheets("ACTIVITY").Range("C5").Value = "INVESTING" Then
Dim Baris1, totalBaris1 As Long
totalBaris1 = ThisWorkbook.Sheets("INVESTING HISTORY").Cells.Rows.Count
Baris1 = ThisWorkbook.Sheets("INVESTING HISTORY").Cells(totalBaris1, 2).End(xlUp).Row + 1
ThisWorkbook.Sheets("INVESTING HISTORY").Range("A" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E8").Value
ThisWorkbook.Sheets("INVESTING HISTORY").Range("B" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E13").Value
ThisWorkbook.Sheets("INVESTING HISTORY").Range("C" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E9").Value
ThisWorkbook.Sheets("INVESTING HISTORY").Range("D" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E10").Value
ThisWorkbook.Sheets("INVESTING HISTORY").Range("E" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E11").Value
ThisWorkbook.Sheets("INVESTING HISTORY").Range("F" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E12").Value
MsgBox "Investing sudah masuk database"
ThisWorkbook.Sheets("ACTIVITY")("E8").Value = ""
ThisWorkbook.Sheets("ACTIVITY")("E9").Value = ""
ThisWorkbook.Sheets("ACTIVITY")("E10").Value = ""
ThisWorkbook.Sheets("ACTIVITY")("E11").Value = ""
ThisWorkbook.Sheets("ACTIVITY")("E12").Value = ""
ElseIf ThisWorkbook.Sheets("ACTIVITY").Range("C5").Value = "RETURN OF INVESTMENT" Then
Dim Baris2, totalBaris2 As Long
totalBaris2 = ThisWorkbook.Sheets("RETURN OF INVESTMENT").Cells.Rows.Count
Baris2 = ThisWorkbook.Sheets("RETURN OF INVESTMENT").Cells(totalBaris2, 2).End(xlUp).Row + 1
ThisWorkbook.Sheets("RETURN OF INVESTMENT").Range("A" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E8").Value
ThisWorkbook.Sheets("RETURN OF INVESTMENT").Range("B" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E9").Value
ThisWorkbook.Sheets("RETURN OF INVESTMENT").Range("D" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E12").Value
MsgBox "Funding sudah masuk database"
ThisWorkbook.Sheets("ACTIVITY").Range("E8").Value = ""
ThisWorkbook.Sheets("ACTIVITY").Range("E9").Value = ""
ThisWorkbook.Sheets("ACTIVITY").Range("E12").Value = ""
End If
End Sub
I get an error yellow line at this line :
ThisWorkbook.Sheets("INVESTING HISTORY").Range("A" & Baris).Value = ThisWorkbook.Sheets("ACTIVITY").Range("E8").Value
I can input the funding, but its getting error when I choose investing and return of investment.
Can you help me for this one? I'm really appreciate if someone can help me. If someone can shorting my code, it was really delightful. Thanks btw.


ThisWorkbook.Sheets("RETURN OF INVESTMENT")but in the screen-shot you've provided it's "RETURN OF INVESTING" - this will result to another errorBarisis suppose to be the first available row at Column B, you should useBaris = ThisWorkbook.Sheets("FUNDING HISTORY").Cells(ThisWorkbook.Sheets("FUNDING HISTORY").Rows.Count , 2).End(xlUp).Row + 1