Consulting

Results 1 to 7 of 7

Thread: Setting the value of a cell to the value of a variable

  1. #1
    VBAX Newbie
    Joined
    Nov 2009
    Posts
    3
    Location

    Setting the value of a cell to the value of a variable

    Hi everyone, I'm really new to VBA so be patient with me here.

    I've set the value of cell AD1 on a worksheet to 4, but it isn't picking this up, I'm wondering if this is to do with the fact that I have hidden the AD column, or due to the fact that there is an error in my code?

    I'll show you what I have so far (I've highlighted what I think is the part you'll need to refer to):

    Public current

    Sub CVariable()
    current = ActiveWorkbook.Worksheets("Sheet1").Range("AD1").Value
    End Sub

    Private Sub NextStu_Click()
    MsgBox "The value of current is:" & current
    End Sub



    Private Sub BackToMenu_Click()
    NewStudent.Hide
    End Sub

    Private Sub StudentSearch_Click()
    AdvancedSearch.Show
    End Sub

    Private Sub Save_Click()
    If ActiveSheet.Cells(current, 2) = "" Then
    current = current
    Else
    current = (current + 1)
    End If
    ActiveSheet.Cells(current, 2).Value = FirstName.Text
    ActiveSheet.Cells(current, 3).Value = LastName.Text
    ActiveSheet.Cells(current, 4).Value = Gender.Text
    ActiveSheet.Cells(current, 5).Value = DOBDay.Text
    ActiveSheet.Cells(current, 6).Value = DOBMonth.Text
    ActiveSheet.Cells(current, 7).Value = DOBYear.Text
    ActiveSheet.Cells(current, 8).Value = Mod1.Text
    ActiveSheet.Cells(current, 9).Value = Mod2.Text
    ActiveSheet.Cells(current, 10).Value = Mod3.Text
    ActiveSheet.Cells(current, 11).Value = Mod4.Text
    ActiveSheet.Cells(current, 12).Value = Mod5.Text
    ActiveSheet.Cells(current, 13).Value = Mod6.Text
    End Sub

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Are you trying to set a public variable?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Newbie
    Joined
    Nov 2009
    Posts
    3
    Location
    I think so?
    I thought that was what was needed?

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Can you briefly describe what you are trying to accomplish?

    Is this classwork?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Newbie
    Joined
    Nov 2009
    Posts
    3
    Location
    It is classwork, basically it's a mark entry system for a university lecturer. They would enter the details of students and their marks, which would be transferred from the userform into a spreadsheet.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Could you clean up the workbook so that it doesn't have any personal info an post it here?

    Hit post reply on the bottom left of the last post and when you have posted your message, scroll down and look for a button that says "manage attachments".

    Alternately, I could post an example of a userform that might give you some ideas. This doesn't sound like a very big project but I will need more info to be able to help you.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Are you getting graded on this? We won't give full solutions for classwork but we can give you pointers and answer your questions.

    In other words, we won't do it all for you but we will help.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •