Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 852201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:33:21+00:00 2026-05-15T07:33:21+00:00

I have a form with 3 textboxes and 1 button. textbox1 has tab index

  • 0

I have a form with 3 textboxes and 1 button.

textbox1 has tab index 0, and it’s text = 1

textbox2 has tab index 1, and it’s text = 2

textbox3 has tab index 2, and it’s text = 3

I want to iterate thru the textboxes and place their values into cells so that…

range("A1").value = txtbox1.text (ie: A1 = "1")
range("A2").value = txtbox2.text (ie: A2 = "2")
range("A3").value = txtbox3.text (ie: A3 = "3")

but what I am getting is…

range("A1").value = txtbox1.text (ie: A1 = "3")
range("A2").value = txtbox2.text (ie: A2 = "2")
range("A3").value = txtbox3.text (ie: A3 = "1")

I have tried reversing the tab index for the text boxes, but it doesn’t change the "backwards iteration".

Is there something I can do to change this so that the loop runs from lowest tab index to highest?

Thanks!

Public Class Form1

   Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      Dim objExcel As New Microsoft.Office.Interop.Excel.Application 'Declaring the object.
      objExcel.Visible = True 'Setting Excel to visible.

      Dim cntrl As Control

      With objExcel
         .Workbooks.Add() 'Adding a workbook.
         .Range("A1").Select() 'Selecting cell A1.
      End With


      'Form contains 3 text boxes, with one number in each (1,2,3), and one button to fire the code in this sub.

      For Each cntrl In Me.Controls 'For every control on the form...
         If TypeOf (cntrl) Is TextBox Then 'If the control is a textbox, then...
            With objExcel
               .ActiveCell.Value = cntrl.Text 'place the control's text in the active cell and...
               .ActiveCell.Offset(1, 0).Activate() 'offset down one row.
            End With
         End If 'If the control is not a textbox (if it's the button), do nothing.
      Next 'Go to the next control.

      objExcel = Nothing 'Release the object.
      GC.Collect() 'Clean up.

   End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:33:21+00:00Added an answer on May 15, 2026 at 7:33 am

    Sounds like it may be the way Excel is iterating over the controls. Have you tried this to see what the output is?

      Dim objExcel As New Microsoft.Office.Interop.Excel.Application 'Declaring the object.
      objExcel.Visible = True 'Setting Excel to visible.
    
      Dim cntrl As Control
    
      With objExcel
         .Workbooks.Add() 'Adding a workbook.
         .Range("A3").Select() 'Selecting cell A3.
      End With
    
    
      'Form contains 3 text boxes, with one number in each (1,2,3), and one button to fire the code in this sub.
    
      For Each cntrl In Me.Controls 'For every control on the form...
         If TypeOf (cntrl) Is TextBox Then 'If the control is a textbox, then...
            With objExcel
               .ActiveCell.Value = cntrl.Text 'place the control's text in the active cell and...
               .ActiveCell.Offset(-1, 0).Activate() 'offset up one row.
            End With
         End If 'If the control is not a textbox (if it's the button), do nothing.
      Next 'Go to the next control.
    
      objExcel = Nothing 'Release the object.
      GC.Collect() 'Clean up.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.