User Input forms - wont switch worksheets

numba

New Member
Joined
Aug 26, 2016
Messages
6
I have created a series of forms that input job tracking data into two different worksheets - Hours into one and Materials into another.
The main menu is opens the form but it doesnt change the worksheet that it is populated to for some reason?
When I click "Enter Hours" It opens the form for staff hours BUT if the last thing I did previously was enter materials it attempts to populate that sheet.

Even though my code specifies the sheet here

erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = txtDate
Cells(erow, 2).Value = CboStaff
Cells(erow, 3).Value = Val(txtNormalHrs.Text)


All the worksheets do seem to stay open in the background. When I am finished I dont think I want the person inputting to see that as much unless they have to perhaps look for an error but I can deal with that once I make sure that the data goes into the right sheet!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
erow is just a number (.row) so the only place you specify the sheet is when you specify the row. You'll need to specify sheet2 before all the lines.
 
Upvote 0
Try this:

Code:
With Sheet2
erow = .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
.Cells(erow, 1).Value = txtDate
.Cells(erow, 2).Value = CboStaff
.Cells(erow, 3).Value = Val(txtNormalHrs.Text)
End With
 
Upvote 0
Try this:

Code:
With Sheet2
erow = .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
.Cells(erow, 1).Value = txtDate
.Cells(erow, 2).Value = CboStaff
.Cells(erow, 3).Value = Val(txtNormalHrs.Text)
End With



Thankyou! Makes sense but didnt work. Will I need to do before each row?
I have ;


Private Sub cmdEnter_Click()


Dim erow As Long
With Sheet6
erow = Sheet6.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = txtDate
Cells(erow, 2).Value = CboStaff
Cells(erow, 3).Value = txtMaterial
Cells(erow, 4).Value = ChkCoil
Cells(erow, 5).Value = Val(txtPrice.Text)
Cells(erow, 7).Value = CboPriceSource
Cells(erow, 8).Value = txtComments
End With
End Sub
 
Upvote 0
The script I sent you should work I test all my scripts but you could use this:

When things do not work you should say what happened. Did you get a error or what. Do not just say
"Did not Work"

Code:
Dim erow As Long
 
 erow = Sheet6.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
 Sheet6.Cells(erow, 1).Value = txtDate
 Sheet6.Cells(erow, 2).Value = CboStaff
 
 etc
 etc
 
Upvote 0
Could this help to solve your problem:

Code:
[COLOR=#333333]Private Sub cmdEnter_Click()[/COLOR]

[COLOR=#333333]Dim erow As Long
[/COLOR]Dim ws as Worksheet

Set ws = sheets("Sheet6")

[COLOR=#333333]With Sheet6[/COLOR]
[COLOR=#333333]erow = Sheet6.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row[/COLOR]
[COLOR=#333333]Cells(erow, 1).Value = txtDate[/COLOR]
[COLOR=#333333]Cells(erow, 2).Value = CboStaff[/COLOR]
[COLOR=#333333]Cells(erow, 3).Value = txtMaterial[/COLOR]
[COLOR=#333333]Cells(erow, 4).Value = ChkCoil[/COLOR]
[COLOR=#333333]Cells(erow, 5).Value = Val(txtPrice.Text)[/COLOR]
[COLOR=#333333]Cells(erow, 7).Value = CboPriceSource[/COLOR]
[COLOR=#333333]Cells(erow, 8).Value = txtComments[/COLOR]
[COLOR=#333333]End With[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
 
Upvote 0
No this line threw up the error - Set ws = sheets("Sheet6")
Runtime error - subscript out of range

Could this help to solve your problem:

Code:
[COLOR=#333333]Private Sub cmdEnter_Click()[/COLOR]

[COLOR=#333333]Dim erow As Long
[/COLOR]Dim ws as Worksheet

Set ws = sheets("Sheet6")

[COLOR=#333333]With Sheet6[/COLOR]
[COLOR=#333333]erow = Sheet6.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row[/COLOR]
[COLOR=#333333]Cells(erow, 1).Value = txtDate[/COLOR]
[COLOR=#333333]Cells(erow, 2).Value = CboStaff[/COLOR]
[COLOR=#333333]Cells(erow, 3).Value = txtMaterial[/COLOR]
[COLOR=#333333]Cells(erow, 4).Value = ChkCoil[/COLOR]
[COLOR=#333333]Cells(erow, 5).Value = Val(txtPrice.Text)[/COLOR]
[COLOR=#333333]Cells(erow, 7).Value = CboPriceSource[/COLOR]
[COLOR=#333333]Cells(erow, 8).Value = txtComments[/COLOR]
[COLOR=#333333]End With[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
 
Upvote 0
Thanks for the explanation (sorry for not giving error). Yes. Worked perfectly when I added to each line. Thank you!
 
Upvote 0

Forum statistics

Threads
1,217,307
Messages
6,135,745
Members
449,962
Latest member
nataliaferlo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top