PC Review


Reply
Thread Tools Rate Thread

Clean up code using WITHs

 
 
Richard
Guest
Posts: n/a
 
      30th Apr 2004
Is there a more efficient way to write this code? For example could I use another with (ActiveSheet)?

With Sheet2
.Cells(varRow, 1).Value = ActiveSheet.Range("G3").Value
.Cells(varRow, 2).Value = ActiveSheet.Range("G4").Value
.Cells(varRow, 3).Value = ActiveSheet.Range("Total").Value
.Cells(varRow, 4).Value = ActiveSheet.Range("B11").Value
.Cells(varRow, 5).Value = ActiveSheet.Range("B12").Value
.Cells(varRow, 6).Value = ActiveSheet.Range("B13").Value
.Cells(varRow, 7).Value = ActiveSheet.Range("B14").Value
.Cells(varRow, 8).Value = ActiveSheet.Range("B15").Value
.Cells(varRow, 9).Value = ActiveSheet.Range("F11").Value
.Cells(varRow, 10).Value = ActiveSheet.Range("F12").Value
.Cells(varRow, 11).Value = ActiveSheet.Range("F13").Value
.Cells(varRow, 12).Value = ActiveSheet.Range("F14").Value
.Cells(varRow, 13).Value = ActiveSheet.Range("F15").Value
end with

Thank you all,

Rick
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RA==?=
Guest
Posts: n/a
 
      30th Apr 2004
Could try calling it

callme 1, "G3"
callme 2, "G4"
callme 3, "Total"
callme 4, "B11"
etc, etc...

private sub callme(x,y)
sheet2.cells(varrow, x).value = activesheet.range(y).value
end sub

----- Richard wrote: -----

Is there a more efficient way to write this code? For example could I use another with (ActiveSheet)?

With Sheet2
.Cells(varRow, 1).Value = ActiveSheet.Range("G3").Value
.Cells(varRow, 2).Value = ActiveSheet.Range("G4").Value
.Cells(varRow, 3).Value = ActiveSheet.Range("Total").Value
.Cells(varRow, 4).Value = ActiveSheet.Range("B11").Value
.Cells(varRow, 5).Value = ActiveSheet.Range("B12").Value
.Cells(varRow, 6).Value = ActiveSheet.Range("B13").Value
.Cells(varRow, 7).Value = ActiveSheet.Range("B14").Value
.Cells(varRow, 8).Value = ActiveSheet.Range("B15").Value
.Cells(varRow, 9).Value = ActiveSheet.Range("F11").Value
.Cells(varRow, 10).Value = ActiveSheet.Range("F12").Value
.Cells(varRow, 11).Value = ActiveSheet.Range("F13").Value
.Cells(varRow, 12).Value = ActiveSheet.Range("F14").Value
.Cells(varRow, 13).Value = ActiveSheet.Range("F15").Value
end with

Thank you all,

Rick

 
Reply With Quote
 
mudraker
Guest
Posts: n/a
 
      30th Apr 2004
Another way



Dim i As Integer
With Sheet2
.Cells(varRow, 1).Value = ActiveSheet.Range("G3").Value
.Cells(varRow, 2).Value = ActiveSheet.Range("G4").Value
.Cells(varRow, 3).Value = ActiveSheet.Range("Total").Value
For i = 4 To 8 Step 1
.Cells(varRow, i).Value = ActiveSheet.Cells(i + 7, "b").Value
Next i
For i = 9 To 13 Step 1
.Cells(varRow, i).Value = ActiveSheet.Cells(i + 2, "f").Value
Next i
End Wit

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

 
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
MultiLine Code Builder, Need Help to Clean Code: Benjamin Microsoft Excel Programming 0 18th Nov 2009 04:40 PM
Clean-up Code Howard Microsoft Excel Programming 4 3rd Dec 2008 02:11 AM
code clean up Lynn Microsoft Dot NET Framework Forms 2 28th Jan 2006 03:37 PM
Nested Withs of Multiple Objects (Parent-Child) Trip Microsoft Excel Programming 0 3rd Nov 2005 08:52 PM
How to obtain database field withs out of datatable? Tony Mouton Microsoft Dot NET Framework 0 4th Feb 2004 10:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:16 PM.