Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Clean up code using WITHs

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Clean up code using WITHs

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clean up code using WITHs

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
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
clean up code a little terilad Excel Discussion (Misc queries) 12 April 12th 10 07:35 PM
Clean Up Code - consolidate steps Frantic Excel-er Excel Discussion (Misc queries) 6 June 30th 05 03:40 PM
Trim function doesn't clean out ASCII Code 160 (Space) Ronald Dodge Excel Worksheet Functions 6 January 27th 05 03:48 AM
Plase help me clean up my code jasonsweeney[_14_] Excel Programming 1 January 22nd 04 07:47 PM
=clean(a1) news.verizon.net Excel Programming 2 August 25th 03 11:08 PM


All times are GMT +1. The time now is 01:25 AM.

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"