I have an application in which I am using vb.net and excel. Daily readings are taken, written into vb.net and then saved into excel. At the moment i have it set so that:

If Gdate = "12 February 2010" Then


                        .Range("C4").Value = TextBox1.Text
                        .Range("C5").Value = TextBox2.Text
                        .Range("C6").Value = TextBox3.Text
                        .Range("C7").Value = TextBox4.Text
                        .Range("C8").Value = TextBox5.Text
                        .Range("C10").Value = TextBox6.Text
                        .Range("C11").Value = TextBox7.Text
                        .Range("C12").Value = TextBox8.Text
                        .Range("C13").Value = TextBox9.Text
                        .Range("C14").Value = TextBox10.Text
                        .Range("C16").Value = TextBox11.Text
                        .Range("C17").Value = TextBox12.Text
                        .Range("C18").Value = TextBox13.Text
                        .Range("C19").Value = TextBox14.Text
                        .Range("C20").Value = TextBox15.Text
                        .Range("C21").Value = TextBox16.Text
                        .Range("C22").Value = TextBox17.Text
                        .Range("C24").Value = TextBox18.Text
                        .Range("C25").Value = TextBox19.Text
                        .Range("C26").Value = TextBox20.Text

End if

At the moment, if the date is the 12th of February the inforation goes into the following cells. I want to be able to say that if the date is the 13th of February that all the data gets added into same cells in column E without having to do

If Gdate = "13 February 2010" Then


                        .Range("E4").Value = TextBox1.Text
                        .Range("E5").Value = TextBox2.Text
                        .Range("E6").Value = TextBox3.Text
                        .Range("E7").Value = TextBox4.Text

etc. Is there a way to do this without having to type it all out manually as it will be over the next year i will need to fill in this data.

Thanks. :D

Try to implement this,

Dim tx as TextBox()={TextBox1,TextBox2,TextBox3,Textbox4}
 Dim dt as Date=Date.Parse(gdate)
 Dim dy as Integer = dt.Day
 Dim cell as String=""

 If dy > 26 Then
    cell = "A" & Chr(64 + dy Mod 26)
 Else
    cell = Chr(dy + 64)
 End If 

 For i As Integer = 0 To tx.GetUpperBound(0)
             .Range(cell & (i + 1)).Value=tx(i).Text
 Next

Hi, thank you for your reply. I tried this and it does not work! I put it in with my code aswell. I did not get any error messages but the information I entered is not saving to the excel file?

Hi, I'm pretty new to this. Can you please tell me why you are referring to 26 in:

If dy > 26 Then cell = "A" & Chr(64 + dy Mod 26)

Thank you.

>why you are referring to 26 in..

Twenty six alphabets. If day number is 27 then column name should be "AA".

Thank you, I understand what you mean now. What does (64 + dy Mod 26) mean please? And also where sould i be implemting your code into mine? Thank you again, you are very helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.