Chrisetiquette Chrisetiquette - 1 year ago 110 Question

Move right to next cell in Excel using

I need to name my headers according to the items I have in a combo box. I'm basically taking the items from a combo box and adding them to the end of an existing header row in a excel sheet, so starting at the first empty cell in the headers row. However, I can't seem to move to the next cell to the right which would be the next header/column name. Here is my code thus far:

For i = 0 To ComboBox1.Items.Count - 1
Dim s As String
s = Convert.ToString(ComboBox1.Items(i))
xlWorkSheet.Range(columnName & "1").Value = s
Next i

ColumnName is the next blank header in that row, Column "L", so from there i would like to populate that cell then move to the right to the next cell.

Answer Source

Loops are so yesterday :]
You can set all headers at once with something like:

Dim headers = ComboBox1.Items.Cast(Of Object).ToArray
xlWorkSheet.Range("A1").Resize(1, headers.Length).Value2 = headers

Also, when you get acceptable answer you should check the green check next to it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download