Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VBA I need some help.

VBA I need some help.

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    code1235813
    wrote on last edited by
    #1

    The problem I am having is I need to enter values in a text box on a form and transfer them to an Excel sheet. I need to be able to input up to 25 "scores" For example I submit 77 then click submit it runs the following code For i = 1 To 25 'count = count + 1 'score = txtscore.Text 'Sheet5.Cells(i, "a").Value = score 'Next i The problem is it enters score for all values A1:A25 I need the score to be entered in A1 then input another number into txtscore which is my text box. Then after I click the submit button I need that value to be placed in A2 and so on and so forth. Any suggestions? Thanks

    I can only open the door... I can't walk you through it.

    C 1 Reply Last reply
    0
    • C code1235813

      The problem I am having is I need to enter values in a text box on a form and transfer them to an Excel sheet. I need to be able to input up to 25 "scores" For example I submit 77 then click submit it runs the following code For i = 1 To 25 'count = count + 1 'score = txtscore.Text 'Sheet5.Cells(i, "a").Value = score 'Next i The problem is it enters score for all values A1:A25 I need the score to be entered in A1 then input another number into txtscore which is my text box. Then after I click the submit button I need that value to be placed in A2 and so on and so forth. Any suggestions? Thanks

      I can only open the door... I can't walk you through it.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I don't know VBA, but

      J-c-K wrote:

      'Sheet5.Cells(i, "a").Value = score

      it seems clear to me that when i is 1, it will go into A1, when it's 2, it will go in to A2, etc.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      C 1 Reply Last reply
      0
      • C Christian Graus

        I don't know VBA, but

        J-c-K wrote:

        'Sheet5.Cells(i, "a").Value = score

        it seems clear to me that when i is 1, it will go into A1, when it's 2, it will go in to A2, etc.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        C Offline
        C Offline
        code1235813
        wrote on last edited by
        #3

        Thanks. It does go into A2 and so. However, I need the value in the text box to go into A1. Then I need the value/variable cleared then once another value is entered in the text box I want that value in A2 then cleared then A3 etc. Private Sub CommandButton1_Click() 'txtscore.Text = "" For i = 1 To 25 ' hours = Cells(i, "b").Value ' rate = Cells(i, "c").Value count = count + 1 score = txtscore.Text Sheet5.Cells(i, "a").Value = score txtcount = Sheet5.Range("B2") txtmean = Sheet5.Range("B3") txtstand = Sheet5.Range("B4") Next i End Sub

        I can only open the door... I can't walk you through it.

        D 1 Reply Last reply
        0
        • C code1235813

          Thanks. It does go into A2 and so. However, I need the value in the text box to go into A1. Then I need the value/variable cleared then once another value is entered in the text box I want that value in A2 then cleared then A3 etc. Private Sub CommandButton1_Click() 'txtscore.Text = "" For i = 1 To 25 ' hours = Cells(i, "b").Value ' rate = Cells(i, "c").Value count = count + 1 score = txtscore.Text Sheet5.Cells(i, "a").Value = score txtcount = Sheet5.Range("B2") txtmean = Sheet5.Range("B3") txtstand = Sheet5.Range("B4") Next i End Sub

          I can only open the door... I can't walk you through it.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You're not going to use any kind of For/Next loop at all in this. You simply keep track of the row you're in in a simple integer variable. Every time you click Submit, or whatever you're calling your button, you put the textbox values in the cells, then increment the variable to point it at the next row. Check the variable to see if it's gone too far and adjust as you see fit. Then, you do nothing... The whole process starts over again on the next button click.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups