PDA

View Full Version : Setting the value of a cell to the value of a variable



EdgeJ
11-05-2009, 09:59 AM
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

lucas
11-05-2009, 12:43 PM
Are you trying to set a public variable?

EdgeJ
11-05-2009, 01:00 PM
I think so?
I thought that was what was needed?

lucas
11-05-2009, 01:01 PM
Can you briefly describe what you are trying to accomplish?

Is this classwork?

EdgeJ
11-05-2009, 02:23 PM
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.

lucas
11-05-2009, 02:53 PM
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.

lucas
11-05-2009, 02:54 PM
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.