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

Hi,
I'm a beginner VB and I'm trying to modify this code so that it would
subtract column H against column F and put the resutl in column K...it should
do that until there is a blank space in column D. I can't seemed to get it
working...it only does H2-F2 and not for all the rows...any idea??

Row = 1
With Sheets("Data")
Range("K2").Select
Do While .Range("D" & Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
selection.NumberFormat = "dd h:mm:ss"
Row = Row + 1
Loop
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default help modify code

...it only does H2-F2 and not for all the rows...any idea??
Yep. The ActiveCell/Selection never moves off of K2.

The following aircode doesn't rely on Selection or ActiveCell, which are
performance hogs. However, there are lots of ways to do this.

iRow = 2
With Sheets("Data")
Do While .Range("D" & iRow-1) < ""
.Range("K" & iRow).FormulaR1C1 = "=RC[-3]-RC[-5]"
.Range("K" & iRow).NumberFormat = "dd h:mm:ss"
iRow = iRow + 1
Loop
End With

--
HTH,
George



"Don Doan" wrote in message
...
Hi,
I'm a beginner VB and I'm trying to modify this code so that it would
subtract column H against column F and put the resutl in column K...it
should
do that until there is a blank space in column D. I can't seemed to get it
working...it only does H2-F2 and not for all the rows...any idea??

Row = 1
With Sheets("Data")
Range("K2").Select
Do While .Range("D" & Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
selection.NumberFormat = "dd h:mm:ss"
Row = Row + 1
Loop
End With



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default help modify code

This should work.

With Sheets("Data")
Range("K2").Select
Do While .Range("D" & ActiveCell.Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
selection.NumberFormat = "dd h:mm:ss"
ActiveCell.Offset(1, 0).Activate
Loop
End With

This will also do what you want.

With Sheets("Data")
lastRow = .Cells(Rows.Count, 4).End(xlUp).Row
.Range("K2:K" & lastRow).NumberFormat = "dd h:mm:ss"
End With



"Don Doan" wrote:

Hi,
I'm a beginner VB and I'm trying to modify this code so that it would
subtract column H against column F and put the resutl in column K...it should
do that until there is a blank space in column D. I can't seemed to get it
working...it only does H2-F2 and not for all the rows...any idea??

Row = 1
With Sheets("Data")
Range("K2").Select
Do While .Range("D" & Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
selection.NumberFormat = "dd h:mm:ss"
Row = Row + 1
Loop
End With

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default help modify code

First, you can't use the variable ROW it is a reserved word. change to
RowCount. I simplified the code so it is easy to understand. You don't need
select and you don't need offsets.

RowCount = 1
With Sheets("Data")
Do While .Range("D" & RowCount) < ""
Range("K" & RowCount).Formula = "=H" & RowCount & "-F" & RowCount
Range("K" & RowCount).NumberFormat = "dd h:mm:ss"
RowCount = RowCount + 1
Loop
End With


"Don Doan" wrote:

Hi,
I'm a beginner VB and I'm trying to modify this code so that it would
subtract column H against column F and put the resutl in column K...it should
do that until there is a blank space in column D. I can't seemed to get it
working...it only does H2-F2 and not for all the rows...any idea??

Row = 1
With Sheets("Data")
Range("K2").Select
Do While .Range("D" & Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
selection.NumberFormat = "dd h:mm:ss"
Row = Row + 1
Loop
End With

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default help modify code

You need the cursor to move down a cell each time - the extra line below
should do it:

Row = 1
With Sheets("Data")
Range("K2").Select
Do While .Range("D" & Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
activecell.offset(1,0).select
selection.NumberFormat = "dd h:mm:ss"
Row = Row + 1
Loop
End With

"Don Doan" wrote:

Hi,
I'm a beginner VB and I'm trying to modify this code so that it would
subtract column H against column F and put the resutl in column K...it should
do that until there is a blank space in column D. I can't seemed to get it
working...it only does H2-F2 and not for all the rows...any idea??

Row = 1
With Sheets("Data")
Range("K2").Select
Do While .Range("D" & Row) < ""
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-5]"
selection.NumberFormat = "dd h:mm:ss"
Row = Row + 1
Loop
End With

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
Modify code bigmaas Excel Discussion (Misc queries) 2 February 16th 10 10:51 AM
Modify Code Richard Excel Worksheet Functions 0 March 13th 08 08:19 PM
Modify existing code to dynamic code Ixtreme Excel Programming 5 August 31st 07 11:42 AM
almost there ... code modify help Ray Excel Programming 1 March 29th 07 12:58 PM
Modify code in UDF Biff Excel Programming 9 August 31st 05 04:41 AM


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