Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to improve this code?

Hi,

I save all the data of each invoice in one row of my DATA sheet. Belo
is my sub doing that. In fact, it is much bigger, I truncated it a bi
in this example.

I offset one column for each individual data of the invoice.

I suspect that:

ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("L12")

is not the ultimate way of doing it. But it is working fine. I jus
want to improve my coding as much as I can.

Any suggestions?

Thanks!

Alain



Sub Save_And_New_Invoice()
Dim Line
Application.ScreenUpdating = False
Sheets("Data").Visible = True
Sheets("Data").Select
Line = LastLine(Sheets("Data"))

Range("A1").Select
ActiveCell.Offset(Line, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("L6")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("L12")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("E12")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("E13")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("E14")

Range("A1").Select
Sheets("Invoice").Select
ActiveWorkbook.Save
Sheets("Data").Visible = False
Application.ScreenUpdating = True
Application.Run "New_Invoice"
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to improve this code?

Alian,

Try something like this. You'll have to do all your lines the same way

ActiveCell.Offset(Line, 0).Range("A1") = Sheets("invoice").Range("L6")
ActiveCell.Offset(0, 1).Range("A1")= Sheets("invoice").Range("L12")

HTH

Charle

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to improve this code?

Alian

This is the code I would use

Sub Save_And_New_Invoice()
Dim WsData As Worksheet
Dim WsInvoice As Worksheet

Dim lRow as long

Set WsData = Sheets("data")
Set WsInvoice = Sheets("invoice")

Application.ScreenUpdating = False
lrow= LastLine(WsData)
WsData.Cells(lrow, "a") = WsInvoice.Range("L6")
WsData.Cells(lrow, "b") = WsInvoice.Range("L12")
WsData.Cells(lrow, "c") = WsInvoice.Range("e12")
WsData.Cells(lrow, "d") = WsInvoice.Range("e13")
WsData.Cells(lrow, "e") = WsInvoice.Range("e14")

ActiveWorkbook.Save
Application.ScreenUpdating = True
Application.Run "New_Invoice"
End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to improve this code?

You suspect right. The mantra of the group is that it is rarely necessary to
do a select.

Sub Save_And_New_Invoice()
Dim Line
Application.ScreenUpdating = False
Line = LastLine(Sheets("Data"))

With ActiveCell
.Offset(Line, 0).Range("A1").Value = Sheets("invoice").Range("L6")
.Offset(Line, 1).Value = Sheets("invoice").Range("L12")
.Offset(Line, 2).Value = Sheets("invoice").Range("E12")
.Offset(Line, 3).Value = Sheets("invoice").Range("E13")
.Offset(Line, 4).Value = Sheets("invoice").Range("E14")
End With

Range("A1").Select
Sheets("Invoice").Select
ActiveWorkbook.Save
Sheets("Data").Visible = False
Application.ScreenUpdating = True
Application.Run "New_Invoice"
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"alainB " wrote in message
...
Hi,

I save all the data of each invoice in one row of my DATA sheet. Below
is my sub doing that. In fact, it is much bigger, I truncated it a bit
in this example.

I offset one column for each individual data of the invoice.

I suspect that:

ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("L12")

is not the ultimate way of doing it. But it is working fine. I just
want to improve my coding as much as I can.

Any suggestions?

Thanks!

Alain



Sub Save_And_New_Invoice()
Dim Line
Application.ScreenUpdating = False
Sheets("Data").Visible = True
Sheets("Data").Select
Line = LastLine(Sheets("Data"))

Range("A1").Select
ActiveCell.Offset(Line, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("L6")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("L12")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("E12")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("E13")
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = Sheets("invoice").Range("E14")

Range("A1").Select
Sheets("Invoice").Select
ActiveWorkbook.Save
Sheets("Data").Visible = False
Application.ScreenUpdating = True
Application.Run "New_Invoice"
End Sub


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to improve this code?

Hi,

Thanks everybody!

I also see that it is not even necessary to select the sheet and mak
it visible to work on it.

Thanks again!

Alain (not Alian

--
Message posted from http://www.ExcelForum.com

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
Need to Improve Code Copying/Pasting Between Workbooks David Excel Discussion (Misc queries) 1 January 6th 06 03:56 AM
How can I set the tab to improve navigation in Excel? stefanie Setting up and Configuration of Excel 1 November 9th 05 07:32 PM
Help improve mySchedule Please StevenPar Excel Discussion (Misc queries) 0 October 23rd 05 06:29 AM
How can improve this formula? Metallo Excel Worksheet Functions 7 January 27th 05 05:49 PM
Need to improve a formula Brian Excel Worksheet Functions 2 December 9th 04 07:17 PM


All times are GMT +1. The time now is 05:49 PM.

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

About Us

"It's about Microsoft Excel"