Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MC MC is offline
external usenet poster
 
Posts: 29
Default Help with formula in vb coding


Hi, I am using excel 2003. I have a spreadsheet that has approx 3000 lines.
I am trying to code Col A to equal the values in Col C, D & E. And Col B = H
- G. The following code works, but takes a long time to execute:
xl_WksheetAC05_52712.Range("C2").Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(-2,0 ).Value = ActiveCell.Value &
ActiveCell.Offset(0, 1).Value & ActiveCell.Offset(0, 2).Value
ActiveCell.Offset(-1, 0).Value = ActiveCell.Offset(0, 5).Value
- ActiveCell.Offset(0, 4).Value
ActiveCell.Offset(1, 0).Select
Loop

Is there a better solution? Thanks in advance.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Help with formula in vb coding


Try this:

Sub AddFormulas()
Dim LR As Long
'Activate xl_WksheetAC05_52712 (must set object variable first)
xl_WksheetAC05_52712.Activate
'Find the last cell in row C
LR& = Range("C2").End(xlDown).Row
'Add formulas in row 2
Range("A2").Formula = "=SUM(RC[2]:RC[4])"
Range("B2").Formula = "=RC[6]-RC[5]"
'Use AutoFill to copy the formulas down
Range("A2:B2").Select
Selection.AutoFill Destination:=Range("A2:B" & LR&)
Calculate
End Sub

Hope this helps,

Hutch

"mc" wrote:

Hi, I am using excel 2003. I have a spreadsheet that has approx 3000 lines.
I am trying to code Col A to equal the values in Col C, D & E. And Col B = H
- G. The following code works, but takes a long time to execute:
xl_WksheetAC05_52712.Range("C2").Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(-2,0 ).Value = ActiveCell.Value &
ActiveCell.Offset(0, 1).Value & ActiveCell.Offset(0, 2).Value
ActiveCell.Offset(-1, 0).Value = ActiveCell.Offset(0, 5).Value
- ActiveCell.Offset(0, 4).Value
ActiveCell.Offset(1, 0).Select
Loop

Is there a better solution? Thanks in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
MC MC is offline
external usenet poster
 
Posts: 29
Default Help with formula in vb coding

Thanks, Tom for the help, it worked.

"Tom Hutchins" wrote:

Try this:

Sub AddFormulas()
Dim LR As Long
'Activate xl_WksheetAC05_52712 (must set object variable first)
xl_WksheetAC05_52712.Activate
'Find the last cell in row C
LR& = Range("C2").End(xlDown).Row
'Add formulas in row 2
Range("A2").Formula = "=SUM(RC[2]:RC[4])"
Range("B2").Formula = "=RC[6]-RC[5]"
'Use AutoFill to copy the formulas down
Range("A2:B2").Select
Selection.AutoFill Destination:=Range("A2:B" & LR&)
Calculate
End Sub

Hope this helps,

Hutch

"mc" wrote:

Hi, I am using excel 2003. I have a spreadsheet that has approx 3000 lines.
I am trying to code Col A to equal the values in Col C, D & E. And Col B = H
- G. The following code works, but takes a long time to execute:
xl_WksheetAC05_52712.Range("C2").Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(-2,0 ).Value = ActiveCell.Value &
ActiveCell.Offset(0, 1).Value & ActiveCell.Offset(0, 2).Value
ActiveCell.Offset(-1, 0).Value = ActiveCell.Offset(0, 5).Value
- ActiveCell.Offset(0, 4).Value
ActiveCell.Offset(1, 0).Select
Loop

Is there a better solution? Thanks in advance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Help with formula in vb coding

WITH xl_WksheetAC05_52712.
WITH .Range(.Range("C2") , .Range("C2").End(xlDown) ).Offset(,-2)
.FormulaR1C1= "=RC3 & RC4 & RC5"
END WITH
WITH .Range(.Range("C2") , .Range("C2").End(xlDown) ).Offset(,-1)
.FormulaR1C1= "=RC8"
END WITH
END WITH

"mc" wrote in message
...
Hi, I am using excel 2003. I have a spreadsheet that has approx 3000
lines.
I am trying to code Col A to equal the values in Col C, D & E. And Col B
= H
- G. The following code works, but takes a long time to execute:
xl_WksheetAC05_52712.Range("C2").Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(-2,0 ).Value = ActiveCell.Value &
ActiveCell.Offset(0, 1).Value & ActiveCell.Offset(0, 2).Value
ActiveCell.Offset(-1, 0).Value = ActiveCell.Offset(0, 5).Value
- ActiveCell.Offset(0, 4).Value
ActiveCell.Offset(1, 0).Select
Loop

Is there a better solution? Thanks in advance.




  #6   Report Post  
Posted to microsoft.public.excel.programming
MC MC is offline
external usenet poster
 
Posts: 29
Default Help with formula in vb coding


Thanks for the help, it worked.

"Patrick Molloy" wrote:

WITH xl_WksheetAC05_52712.
WITH .Range(.Range("C2") , .Range("C2").End(xlDown) ).Offset(,-2)
.FormulaR1C1= "=RC3 & RC4 & RC5"
END WITH
WITH .Range(.Range("C2") , .Range("C2").End(xlDown) ).Offset(,-1)
.FormulaR1C1= "=RC8"
END WITH
END WITH

"mc" wrote in message
...
Hi, I am using excel 2003. I have a spreadsheet that has approx 3000
lines.
I am trying to code Col A to equal the values in Col C, D & E. And Col B
= H
- G. The following code works, but takes a long time to execute:
xl_WksheetAC05_52712.Range("C2").Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(-2,0 ).Value = ActiveCell.Value &
ActiveCell.Offset(0, 1).Value & ActiveCell.Offset(0, 2).Value
ActiveCell.Offset(-1, 0).Value = ActiveCell.Offset(0, 5).Value
- ActiveCell.Offset(0, 4).Value
ActiveCell.Offset(1, 0).Select
Loop

Is there a better solution? Thanks in advance.


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
Coding Formula Richard Excel Programming 2 September 21st 07 01:36 PM
Coding a SumProduct formula Otto Moehrbach Excel Programming 2 October 28th 06 04:54 PM
Help with Coding a Formula Please Paul Black Excel Programming 8 August 19th 05 02:04 PM
Formula Color Coding Andrew Excel Discussion (Misc queries) 5 March 25th 05 08:41 PM
vba coding for formula in cell RDP1 Excel Programming 2 February 7th 05 10:05 PM


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