PC Review


Reply
Thread Tools Rate Thread

Code Improvement

 
 
=?Utf-8?B?WmFhaGly?=
Guest
Posts: n/a
 
      1st May 2007
Hi

I have the ffg cade to enter data to a sheet. It works fine but how can i
improve it as to shorten it.......

Sub ActualAdd()
ActiveCell.FormulaR1C1 = frmMain.txt2.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt3.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt4.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt5.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt6.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt7.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt8.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt9.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt10.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt11.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt12.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt13.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt14.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = frmMain.txt15.Text

Range("A3").Select
Selection.CurrentRegion.Select
Selection.Name = "CustomerInfo"
Selection.HorizontalAlignment = xlLeft
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


End Sub

Thanx
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      1st May 2007
Zaahir,

here's one suggestion.

Sub ActualAdd()
Dim c As Range
Dim i As Integer

Set c = ActiveCell
For i = 2 To 15
c.FormulaR1C1 = frmMain.Controls("txt" & i).Text
Set c = c.Offset(0, 1)
Next i

With Range("A3").CurrentRegion
.Name = "CustomerInfo"
.HorizontalAlignment = xlLeft
.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With

End Sub


--
Hope that helps.

Vergel Adriano


"Zaahir" wrote:

> Hi
>
> I have the ffg cade to enter data to a sheet. It works fine but how can i
> improve it as to shorten it.......
>
> Sub ActualAdd()
> ActiveCell.FormulaR1C1 = frmMain.txt2.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt3.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt4.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt5.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt6.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt7.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt8.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt9.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt10.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt11.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt12.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt13.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt14.Text
> ActiveCell.Offset(0, 1).Select
> ActiveCell.FormulaR1C1 = frmMain.txt15.Text
>
> Range("A3").Select
> Selection.CurrentRegion.Select
> Selection.Name = "CustomerInfo"
> Selection.HorizontalAlignment = xlLeft
> Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
> OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
> DataOption1:=xlSortNormal
>
>
> End Sub
>
> Thanx

 
Reply With Quote
 
=?Utf-8?B?WmFhaGly?=
Guest
Posts: n/a
 
      1st May 2007
wow...excellent.
thanx stax Vergel

"Vergel Adriano" wrote:

> Zaahir,
>
> here's one suggestion.
>
> Sub ActualAdd()
> Dim c As Range
> Dim i As Integer
>
> Set c = ActiveCell
> For i = 2 To 15
> c.FormulaR1C1 = frmMain.Controls("txt" & i).Text
> Set c = c.Offset(0, 1)
> Next i
>
> With Range("A3").CurrentRegion
> .Name = "CustomerInfo"
> .HorizontalAlignment = xlLeft
> .Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
> OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
> DataOption1:=xlSortNormal
> End With
>
> End Sub
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "Zaahir" wrote:
>
> > Hi
> >
> > I have the ffg cade to enter data to a sheet. It works fine but how can i
> > improve it as to shorten it.......
> >
> > Sub ActualAdd()
> > ActiveCell.FormulaR1C1 = frmMain.txt2.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt3.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt4.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt5.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt6.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt7.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt8.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt9.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt10.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt11.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt12.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt13.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt14.Text
> > ActiveCell.Offset(0, 1).Select
> > ActiveCell.FormulaR1C1 = frmMain.txt15.Text
> >
> > Range("A3").Select
> > Selection.CurrentRegion.Select
> > Selection.Name = "CustomerInfo"
> > Selection.HorizontalAlignment = xlLeft
> > Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
> > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
> > DataOption1:=xlSortNormal
> >
> >
> > End Sub
> >
> > Thanx

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Further improvement to this IP address sorting code. lawrenceabrown@gmail.com Microsoft Excel Misc 0 12th May 2009 06:28 AM
Improvement to code Brad Microsoft Excel Programming 2 15th Apr 2009 08:39 PM
c# xml code improvement suggestions Peted Microsoft C# .NET 2 20th Jan 2009 07:54 PM
Does this code need improvement? Pwood57@gmail.com Microsoft Access Form Coding 8 6th Dec 2006 02:53 AM
Hlookup Code Improvement Suggestions =?Utf-8?B?dGlt?= Microsoft Excel Programming 2 4th Apr 2005 05:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.