Help with form variable user option

HDfatboy03

Board Regular
Joined
May 23, 2010
Messages
62
Hello

I am creating a time sheet workbook. I've figured out how to have the punches go to a table and a general journal, based on Start, go to break, back from break, go to lunch and back from lunch and go home.

What I am wanting to do ... is have a seperate work sheet for each employee. I work for a small company with only 7 employees. So based on the entry for txtName (I want txtName to be the variable the controls ws2) ... I want the input to go to the appropriate worksheet for that employee base on their name (ex Pam, Bob, Brad ...etc).

This is what I have so far. X2 is where I am having problems.

S T A R T C O D E

Private Sub cmdADD5_Click()

Dim iRow As Long
Dim x As Long
x = CLng(Me.txtLoc.Text)

Dim x2 As Long
x2 = CLng(Me.txtName.Text)

Dim ws As Worksheet
Dim ws2 As Worksheet

Set ws = Worksheets("GeneralJournal")
Set ws2 = Worksheets("x2")

'find first empty row in database - THIS WORKS
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'copy the DATA to databases - THIS WORKS
ws.Cells(iRow, 1).Value = txtDate.Value
ws2.Cells(x, "D").Value = Me.txtDate.Value
ws.Cells(iRow, 2).Value = txtName.Value
ws2.Cells(2, "B").Value = Me.txtName.Value
ws.Cells(iRow, 3).Value = txtTime.Value
ws2.Cells(x, "G").Value = Me.txtTime.Value
ws.Cells(iRow, 4).Value = cboPunch.Value
ws2.Cells(x, "F").Value = Me.cboPunch.Value
'ws2.Cells(x, "C").Value = Me.txtLoc.Value

'clear the data - THIS WORKS
txtName.Value = ""
txtTime.Value = ""
cboPunch.Value = ""
txtDay.Value = ""

End Sub

E N D C O D E
 

doofusboy

Well-known Member
Joined
Oct 14, 2003
Messages
1,325
Have you tried something like:

Code:
Dim x2 As [COLOR=red][B]String[/B][/COLOR]
[COLOR=red][B]x2 = Me.txtName.Text
[/B][/COLOR]
Dim ws As Worksheet
Dim ws2 As Worksheet

Set ws = Worksheets("GeneralJournal")
Set ws2 = Sheets([COLOR=red][B]x2[/B][/COLOR])
 

HDfatboy03

Board Regular
Joined
May 23, 2010
Messages
62
thanks so much ... it worked ... you are the BEST. You saved me alot of time

HDfatboy03
 

Forum statistics

Threads
1,081,850
Messages
5,361,687
Members
400,648
Latest member
mamamia93

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top