Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Code Improvement

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Code Improvement

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Code Improvement

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Further improvement to this IP address sorting code. [email protected] Excel Discussion (Misc queries) 0 May 12th 09 06:28 AM
RowSource for Combobox Improvement Tom Ogilvy Excel Programming 0 March 24th 07 04:35 PM
Improvement for office Robert Adams, from Argentina Excel Discussion (Misc queries) 2 May 30th 06 10:32 PM
HLOOKUP improvement? Brad Excel Worksheet Functions 0 June 13th 05 07:01 PM


All times are GMT +1. The time now is 06:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"