Spreedsheet with Form Problem,Dont know my VBA well enough.

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
826
Office Version
  1. 365
Platform
  1. Windows

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi and welcome to the forum.

Your RowCount is finding the Last Used Row, you need to add one to get the Next available row.

Because you have so many controls I wouldn't advise using the Offset function, you will run out of fingers trying to figure out where you are sending the values.

Instead I would specify the Range. It makes the code easier to read. For example:

Code:
   [COLOR=darkblue]With[/COLOR] Worksheets("Cutting Form")
      .Range("A" & RowCount).Value = Me.cboMaterialFrom.Value
      .Range("B" & RowCount).Value = Me.txtMaterialCode.Value
 
[COLOR=seagreen]  '[/COLOR]
[COLOR=seagreen]  'others go here[/COLOR]
[COLOR=seagreen]  '[/COLOR]
 
[COLOR=navy]  End With[/COLOR]


You can set the tab order for the controls either via the Properties Window or by clicking on View => Tab Order.

Try this for clearing the contents of the controls:
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] CommandButtonClearForm_Click()
   [COLOR=darkblue]Dim[/COLOR] ctl [COLOR=darkblue]As[/COLOR] Control
 
   [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] ctl [COLOR=darkblue]In[/COLOR] Me.Controls
      [COLOR=darkblue]If[/COLOR] TypeName(ctl) = "TextBox" Or _
         TypeName(ctl) = "ComboBox" [COLOR=darkblue]Then[/COLOR]
         ctl.Value = ""
      [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
   [COLOR=darkblue]Next[/COLOR] ctl
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps to get you started,
Bertie
 
Upvote 0
Hi and welcome to the forum.

Your RowCount is finding the Last Used Row, you need to add one to get the Next available row.

Because you have so many controls I wouldn't advise using the Offset function, you will run out of fingers trying to figure out where you are sending the values.

Instead I would specify the Range. It makes the code easier to read. For example:

Code:
   [COLOR=darkblue]With[/COLOR] Worksheets("Cutting Form")
      .Range("A" & RowCount).Value = Me.cboMaterialFrom.Value
      .Range("B" & RowCount).Value = Me.txtMaterialCode.Value
 
[COLOR=seagreen] '[/COLOR]
[COLOR=seagreen] 'others go here[/COLOR]
[COLOR=seagreen] '[/COLOR]
 
[COLOR=navy] End With[/COLOR]


You can set the tab order for the controls either via the Properties Window or by clicking on View => Tab Order.

Try this for clearing the contents of the controls:
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] CommandButtonClearForm_Click()
   [COLOR=darkblue]Dim[/COLOR] ctl [COLOR=darkblue]As[/COLOR] Control
 
   [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] ctl [COLOR=darkblue]In[/COLOR] Me.Controls
      [COLOR=darkblue]If[/COLOR] TypeName(ctl) = "TextBox" Or _
         TypeName(ctl) = "ComboBox" [COLOR=darkblue]Then[/COLOR]
         ctl.Value = ""
      [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
   [COLOR=darkblue]Next[/COLOR] ctl
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps to get you started,
Bertie

Thanks Bertie
That will Help alot.
 
Upvote 0

Forum statistics

Threads
1,216,182
Messages
6,129,369
Members
449,506
Latest member
nomvula

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