Compile error: For without Next

NewbieVBie

Board Regular
Joined
Jan 30, 2003
Messages
65
i am consistantly getting a Compile error:
saying:

For Without Next.
what does this mean and how can i resolve it?
(the debug highlights the End Sub line of the code)
 
If c.Value = NAMECB.Value Then

am getting a type mismatch error in this line of coding would this be because the code is in the combobox called NAMECB

also the rest of the code:
would it be something like:

DAYREQUESTTB.value & "

then i get stuck because from the code i have most of it appears to be msgbox coding and i cant use that. so what could i use?

thanks for your time and patience with this
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Sorry, that's my fault.

For Each c in Columns(i)

should be:

For Each c in Columns(i).Cells

Let's get that bit working first.
 
Upvote 0
now ive got the name of the user into the combobox NAMECB. I have the code:

Private Sub ComboBox2_Change()
Dim r As Long
Dim Src As String
r = ComboBox2.ListIndex + 1
Src = ComboBox2.RowSource
Private Sub ComboBox2_Change()
Dim r As Long
Dim Src As String
r = ComboBox2.ListIndex + 1
Src = ComboBox2.RowSource
ENTITLEMENTTB.Value = Range(Src).Cells(r, 2)
DAY2DATETB.Value = Range(Src).Cells(r, 3)
REMAINTB.Value = Range(Src).Cells(r, 4)
End Sub

would that bring the values in the entitlement, remaining, day to date columns in the worksheet in the textboxes?
 
Upvote 0
ok ive got that to work, which means ive got the users entitlement, taken and remaining holiday in the textboxes, now is it possible to code those boxes so the values in them change when the user adds a number to another textbox?

so the entitlement doesn't change but the days taken value gets the number added to it and the remaining value gets the subtracted?
 
Upvote 0
Try:

Private Sub DAY2DATETB_AfterUpdate()
REMAINTB.Value = Val(ENTITLEMENTTB.Value) - Val(DAY2DATETB.Value)
End Sub
 
Upvote 0
a strange problem now...nothing happens, i inserted the code in the DAY2DATETB textbox, and ran the userform, seleected a user entered a value in DAYREQUESTTB to book that as holiday and clicked the enter button and the userform closed and VBA editor came up, no debugger, no save or print (which should happen because of my application.run macros on the enter button)
 
Upvote 0
Maybe that event only fires when the user enters data.

If you are populating it after validating DAYREQUESTTB, then you need to also populate REMAINTB. So in your Button procedure:

DAY2DATETB.Value = DAYREQUESTTB.Value
REMAINTB.Value = Val(ENTITLEMENTTB.Value) - Val(DAY2DATETB.Value)
 
Upvote 0
the code on the combobox that contains the name

For Each c In Columns(i).Cells

has highlighted as a 1004 error, like we had above when the line read:

For Each c In Columns(i)

can you explain the function of the 'c'

and also the function of this code:

DAY2DATETB.Value = DAYREQUESTTB.Value
REMAINTB.Value = Val(ENTITLEMENTTB.Value) - Val(DAY2DATETB.Value)

does the '-' and '+' function work as in a normal sum?
 
Upvote 0
c is a Range Object - in this case a cell. Columns(i).Cells returns a collection of cells and the For Each Next loops around them.

DAY2DATETB.Value = DAYREQUESTTB.Value

puts what is in TextBox DAYREQUESTTB in TextBox DAY2DATETB.

REMAINTB.Value = Val(ENTITLEMENTTB.Value) - Val(DAY2DATETB.Value)

puts what is in TextBox ENTITLEMENTTB less what is in TextBox DAY2DATETB in TextBox REMAINTB.

Yes, the '-' and '+' function work as normal arithmetic operators, although '+' can also be used as a concatenation operation (I always use & for that).
 
Upvote 0

Forum statistics

Threads
1,216,469
Messages
6,130,802
Members
449,595
Latest member
jhester2010

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