Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default a way to make this more compact ??

aWS.Range("B2").Value = (aWS.Range("H7") - aWS.Range("A2").Value) * 100
aWS.Range("B4").Value = (aWS.Range("H7") - aWS.Range("A4").Value) * 100
aWS.Range("B6").Value = (aWS.Range("H7") - aWS.Range("A6").Value) * 100
aWS.Range("B8").Value = (aWS.Range("H7") - aWS.Range("A8").Value) * 100
aWS.Range("B10").Value = (aWS.Range("H7") - aWS.Range("A10").Value) * 100
aWS.Range("B12").Value = (aWS.Range("H7") - aWS.Range("A12").Value) * 100
aWS.Range("B14").Value = (aWS.Range("H7") - aWS.Range("A14").Value) * 100
etc etc....
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default a way to make this more compact ??

something like this should work. just change the 20 to your last row or use a
lastrow variable if it's all the way down the sheet

Sub test()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("aWS")
For i = 2 To 20 Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next
End Sub

or using the lastrow variable

Sub test2()
Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("aWS")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next

End Sub


--


Gary


"pls123" wrote in message
...
aWS.Range("B2").Value = (aWS.Range("H7") - aWS.Range("A2").Value) * 100
aWS.Range("B4").Value = (aWS.Range("H7") - aWS.Range("A4").Value) * 100
aWS.Range("B6").Value = (aWS.Range("H7") - aWS.Range("A6").Value) * 100
aWS.Range("B8").Value = (aWS.Range("H7") - aWS.Range("A8").Value) * 100
aWS.Range("B10").Value = (aWS.Range("H7") - aWS.Range("A10").Value) * 100
aWS.Range("B12").Value = (aWS.Range("H7") - aWS.Range("A12").Value) * 100
aWS.Range("B14").Value = (aWS.Range("H7") - aWS.Range("A14").Value) * 100
etc etc....



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default a way to make this more compact ??

ty gary this seems what i was looking for, i will add it to my page soon


"Gary Keramidas" wrote:

something like this should work. just change the 20 to your last row or use a
lastrow variable if it's all the way down the sheet

Sub test()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("aWS")
For i = 2 To 20 Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next
End Sub

or using the lastrow variable

Sub test2()
Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("aWS")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next

End Sub


--


Gary


"pls123" wrote in message
...
aWS.Range("B2").Value = (aWS.Range("H7") - aWS.Range("A2").Value) * 100
aWS.Range("B4").Value = (aWS.Range("H7") - aWS.Range("A4").Value) * 100
aWS.Range("B6").Value = (aWS.Range("H7") - aWS.Range("A6").Value) * 100
aWS.Range("B8").Value = (aWS.Range("H7") - aWS.Range("A8").Value) * 100
aWS.Range("B10").Value = (aWS.Range("H7") - aWS.Range("A10").Value) * 100
aWS.Range("B12").Value = (aWS.Range("H7") - aWS.Range("A12").Value) * 100
aWS.Range("B14").Value = (aWS.Range("H7") - aWS.Range("A14").Value) * 100
etc etc....




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default a way to make this more compact ??

hi gary ty it seems to work well except for a parenthesis that i added and
works well..
i forgot to tell you how was the dim and set but now i fixed all ty !!


"Gary Keramidas" wrote:

something like this should work. just change the 20 to your last row or use a
lastrow variable if it's all the way down the sheet

Sub test()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("aWS")
For i = 2 To 20 Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next
End Sub

or using the lastrow variable

Sub test2()
Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("aWS")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next

End Sub


--


Gary


"pls123" wrote in message
...
aWS.Range("B2").Value = (aWS.Range("H7") - aWS.Range("A2").Value) * 100
aWS.Range("B4").Value = (aWS.Range("H7") - aWS.Range("A4").Value) * 100
aWS.Range("B6").Value = (aWS.Range("H7") - aWS.Range("A6").Value) * 100
aWS.Range("B8").Value = (aWS.Range("H7") - aWS.Range("A8").Value) * 100
aWS.Range("B10").Value = (aWS.Range("H7") - aWS.Range("A10").Value) * 100
aWS.Range("B12").Value = (aWS.Range("H7") - aWS.Range("A12").Value) * 100
aWS.Range("B14").Value = (aWS.Range("H7") - aWS.Range("A14").Value) * 100
etc etc....




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default a way to make this more compact ??

hi gary it works perfectly and it is easyest to reduce if u don't need 800...
but at equivalent parameters it uses 5.5 instead 4.5 cpu usage !!! ;)
i will keep it anyway and probably use it, byyy and ty

"Gary Keramidas" wrote:

something like this should work. just change the 20 to your last row or use a
lastrow variable if it's all the way down the sheet

Sub test()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("aWS")
For i = 2 To 20 Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next
End Sub

or using the lastrow variable

Sub test2()
Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("aWS")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow Step 2
With ws
.Range("b" & i).Value = .Range("H7").Value - .Range("A" & i).Value * 100
End With
Next

End Sub


--


Gary


"pls123" wrote in message
...
aWS.Range("B2").Value = (aWS.Range("H7") - aWS.Range("A2").Value) * 100
aWS.Range("B4").Value = (aWS.Range("H7") - aWS.Range("A4").Value) * 100
aWS.Range("B6").Value = (aWS.Range("H7") - aWS.Range("A6").Value) * 100
aWS.Range("B8").Value = (aWS.Range("H7") - aWS.Range("A8").Value) * 100
aWS.Range("B10").Value = (aWS.Range("H7") - aWS.Range("A10").Value) * 100
aWS.Range("B12").Value = (aWS.Range("H7") - aWS.Range("A12").Value) * 100
aWS.Range("B14").Value = (aWS.Range("H7") - aWS.Range("A14").Value) * 100
etc etc....




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
compact Access DB from Excel JT Excel Programming 1 May 3rd 07 05:37 PM
This formula needs to be more compact. britgirl Excel Worksheet Functions 2 December 30th 05 01:58 AM
Compact Workbook naiveprogrammer Excel Discussion (Misc queries) 3 October 25th 05 02:48 AM
Compact Steve Excel Programming 4 August 9th 05 06:55 PM
Compact Excel Spreadsheet Newbie Excel Programming 1 February 11th 04 08:41 PM


All times are GMT +1. The time now is 06:04 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"