Im making an app that will use one Excel document that is generated, and place some values from that document to another Excel document, and Im stuck in phase where I need to copy value.
My code:
private void buttonIzvrsi_Click(object sender, EventArgs e)
    {
        if(textBoxPolazna.Text!="" && textBoxKrajnja.Text != "")
        {
            Microsoft.Office.Interop.Excel.Application polazniExcel = new Microsoft.Office.Interop.Excel.Application();
            polazniExcel.FileValidation = MsoFileValidationMode.msoFileValidationSkip;
            Microsoft.Office.Interop.Excel.Workbook polazna = polazniExcel.Workbooks.Open(textBoxPolazna.Text.ToString());
            Excel.Worksheet Polazni = polazniExcel.Sheets[1];//sheet koji treba unijeti 
            Microsoft.Office.Interop.Excel.Application krajnjiExcel = new Microsoft.Office.Interop.Excel.Application();
            krajnjiExcel.FileValidation = MsoFileValidationMode.msoFileValidationSkip;
            Microsoft.Office.Interop.Excel.Workbook krajnja = krajnjiExcel.Workbooks.Open(textBoxKrajnja.Text.ToString());
            Excel.Worksheet Krajnji_PoMT = krajnjiExcel.Sheets["Po mjestu troška"];//sheet po mjestu troska
            Excel.Worksheet Krajnji_Ukupno = krajnjiExcel.Sheets["Ukupno po mjesecima"];//sheet ukupno
            Excel.Range brojRedovaPolazni = Polazni.UsedRange;
            int brojacRedovaPolazni = brojRedovaPolazni.Rows.Count; //broj redova u polaznom excelu 
            Excel.Range brojRedovaKrajnjiMT = Krajnji_PoMT.UsedRange;
            int brojacRedovaKrajnjiMT = brojRedovaKrajnjiMT.Rows.Count;//broj redova u krajnjem excelu sheet mjesto troska
            Excel.Range brojRedovaKrajnjiUkupno = Krajnji_Ukupno.UsedRange;
            int brojacRedovaKrajnjiUkupno = brojRedovaKrajnjiUkupno.Rows.Count;//broj redova u krajnjem excelu sheet ukupno
            List<string> listaMT = new List<string>();
            List<string> PostojeciMjeseci = new List<string>(); //tu planiram trpati mjesece koji postoje
            if (brojacRedovaPolazni == brojacRedovaKrajnjiMT)
            {
                for (int i = 1; i <= 12; i++)
                {
                    if(Polazni.Cells[9, i + 2].Value != null || Polazni.Cells[9, i + 2].Value != "")
                    {
                        listaMT.Add(Polazni.Cells[9, i + 2].Value);
                    }
                }
                PostojeciMjeseci = mjeseci.Intersect(listaMT).ToList(); //ovi mjeseci postoje
                int kolumna = 0;
                for (int i = 0; i < PostojeciMjeseci.Count; i++)
                {
                    for (int j = 1; j < 12; j++)
                    {
                        //MessageBox.Show(Polazni.Cells[9, j + 2].Value);
                        if (string.Equals(PostojeciMjeseci[i], Polazni.Cells[9, j + 2].Value))
                        {
                            #region Broj kolumne
                            if (string.Equals(Polazni.Cells[9, j + 2].Value, "siječanj")) kolumna = 3;//"C";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "veljača")) kolumna = 4;// "D";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "ožujak")) kolumna = 5;// "E";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "travanj")) kolumna = 6;// "F";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "svibanj")) kolumna = 7;// "G";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "lipanj")) kolumna = 8;// "H";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "srpanj")) kolumna = 9;// "I";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "kolovor")) kolumna = 10;// "J";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "rujan")) kolumna = 11;// "K";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "listopad")) kolumna = 12;// "L";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "studeni")) kolumna = 13;// "M";
                            else if (string.Equals(Convert.ToString(Polazni.Cells[9, j + 2].Value), "prosinac")) kolumna = 14;// "N";
                            #endregion
                            //MessageBox.Show("U petlji: "+Polazni.Cells[9, j + 2].Value);
                            string sValue = "";
                            for (int x = 1; x <= brojacRedovaKrajnjiMT - 12; x++)
                            {
                                Krajnji_PoMT.Cells[(x + 12), kolumna].Value = Polazni.Cells[(x + 12), kolumna].Value; 
                            }
                        }
                    }
                }
            }
            else if (brojacRedovaPolazni == brojacRedovaKrajnjiUkupno)
            {
                for (int i = 1; i <= brojacRedovaKrajnjiUkupno; i++)
                {
                }
            }
            else
            {
                MessageBox.Show("Broj redova nije konzistentan s glavnom tablicom.");
            }
            polazna.Close(true, Type.Missing, Type.Missing);
            krajnja.Close(true, Type.Missing, Type.Missing);
            polazniExcel.Quit();
            krajnjiExcel.Quit();
        }
        else
        {
            MessageBox.Show("Unesite obe putanje do Excel datoteka.");
        }
    }
My problem is in the line:
Krajnji_PoMT.Cells[(x + 12), kolumna].Value = Polazni.Cells[(x + 12), kolumna].Value;
I tried many variations but I can never get that value pasted to another Excel. If I say:
Krajnji_PoMT.Cells[(x + 12), kolumna].Value = "test";
then it works. Whats the catch here?
