Anyone can shrink this code?

fucell

New Member
Joined
Jan 3, 2011
Messages
46
is there a way to shorten this code ?

Range("b2").Value = frmquote.txtdate.Value
Range("b3").Value = frmquote.txtquote.Value
Range("b4").Value = frmquote.txtsalesman.Value
Range("b5").Value = frmquote.txtdterequired.Value
Range("b8").Value = frmquote.txtCompName.Value
Range("b9").Value = frmquote.txtadd1.Value
Range("b10").Value = frmquote.cmbo1.Value

frmquote.txtdate.enable = false
frmquote.txtquote.enable = false
frmquote.txtsalesman.enable = false
frmquote.txtdterequired.enable = false
frmquote.txtCompName.enable = false
frmquote.txtadd1.enable = false
frmquote.cmbo1.enable = false

thanks in advance.
 
so since after clicking the commandbuttong.click this code will activated

Code:
ActiveWorkbook.Worksheets("EngInfo").Select
Range("b2").Value = frmquote.txtdate.Value
frmquote.txtdate.enable = false
end sub

I would write that as:
Code:
ActiveWorkbook.Worksheets("EngInfo").Range("b2").Value = frmquote.txtdate.Value
frmquote.txtdate.enable = false
end sub

This way the selection is unchanged after the code is done (if another worksheet than "EngInfo" is selected it will remain selected).

In your form's module you'll probably have a line like
Code:
Private Sub commandbuttong_click
...
End Sub

You'd best put the sub I suggested in that module as well, outside of any other sub or function (like right above the "_click" sub itself).

Kind regards,
Carl Colijn
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,216,309
Messages
6,130,002
Members
449,552
Latest member
8073662045

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