Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default more efficient VBA?

Hello,
I have the following macro:
------------------------
Sub Test()
Range("N2").Select
Do
ActiveCell.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))
End Sub
------------------------
It works fine, the only problem is that it takes time (20 seconds to treat
1000 rows).
Are you aware of any more efficient way of writing this type of code?
Thanks for any hints!
Regards,
Mark


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default more efficient VBA?

Try this:

Sub Test()
Dim x As Long, Rng As Range
x& = Range("L" & Rows.Count).End(xlUp).Row
Set Rng = Range("N2:N" & x&)
Rng.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
Set Rng = Nothing
End Sub

Hope this helps,

Hutch

"markx" wrote:

Hello,
I have the following macro:
------------------------
Sub Test()
Range("N2").Select
Do
ActiveCell.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))
End Sub
------------------------
It works fine, the only problem is that it takes time (20 seconds to treat
1000 rows).
Are you aware of any more efficient way of writing this type of code?
Thanks for any hints!
Regards,
Mark



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default more efficient VBA?

Wow! Quite efficient (took less than 1 second, I think)! Thanks a lot
Hutch!!!

One other question:
I realised that the formula I want to put in this column should be
different:
with "=CONCATENATE(C[-7],C[-6])" I get =CONCATENATE(G:G;H:H), but in fact I
looked for =CONCATENATE(G2;H2) (or even better =G2&H2) for row 2 and so
on...
The result is the same, but any idea how to modify the R1C1 formula to get
the second option?

Thanks once again,
Mark


"Tom Hutchins" wrote in message
...
Try this:

Sub Test()
Dim x As Long, Rng As Range
x& = Range("L" & Rows.Count).End(xlUp).Row
Set Rng = Range("N2:N" & x&)
Rng.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
Set Rng = Nothing
End Sub

Hope this helps,

Hutch

"markx" wrote:

Hello,
I have the following macro:
------------------------
Sub Test()
Range("N2").Select
Do
ActiveCell.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))
End Sub
------------------------
It works fine, the only problem is that it takes time (20 seconds to
treat
1000 rows).
Are you aware of any more efficient way of writing this type of code?
Thanks for any hints!
Regards,
Mark





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default more efficient VBA?

Change Rng.FormulaR1C1 = "=CONCATENATE(RC[-7],C[-6])" to

Rng.FormulaR1C1 = "=CONCATENATE(RC[-7],RC[-6])"

or

Rng.FormulaR1C1 = "=RC[-7]" & "&" & "RC[-6]"

Regards,

Hutch

"markx" wrote:

Wow! Quite efficient (took less than 1 second, I think)! Thanks a lot
Hutch!!!

One other question:
I realised that the formula I want to put in this column should be
different:
with "=CONCATENATE(C[-7],C[-6])" I get =CONCATENATE(G:G;H:H), but in fact I
looked for =CONCATENATE(G2;H2) (or even better =G2&H2) for row 2 and so
on...
The result is the same, but any idea how to modify the R1C1 formula to get
the second option?

Thanks once again,
Mark


"Tom Hutchins" wrote in message
...
Try this:

Sub Test()
Dim x As Long, Rng As Range
x& = Range("L" & Rows.Count).End(xlUp).Row
Set Rng = Range("N2:N" & x&)
Rng.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
Set Rng = Nothing
End Sub

Hope this helps,

Hutch

"markx" wrote:

Hello,
I have the following macro:
------------------------
Sub Test()
Range("N2").Select
Do
ActiveCell.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))
End Sub
------------------------
It works fine, the only problem is that it takes time (20 seconds to
treat
1000 rows).
Are you aware of any more efficient way of writing this type of code?
Thanks for any hints!
Regards,
Mark






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default more efficient VBA?

Hi Mark

Don't select and activate stuff, it's slow and unnecessary.
Also, if you have formulae there, they will recalculate on every cell entry,
it takes time. Turn calculation temporarily off while writing things to
multiple cells.

Try this, it is be pretty fast:

Sub test()
Dim R As Long
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For R = 2 To Cells(Rows.Count, 12).End(xlUp).Row
Cells(R, 14).FormulaR1C1 = _
"=CONCATENATE(C[-7],C[-6])"
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

HTH. Best wishes Harald


"markx" skrev i melding
...
Hello,
I have the following macro:
------------------------
Sub Test()
Range("N2").Select
Do
ActiveCell.FormulaR1C1 = "=CONCATENATE(C[-7],C[-6])"
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))
End Sub
------------------------
It works fine, the only problem is that it takes time (20 seconds to treat
1000 rows).
Are you aware of any more efficient way of writing this type of code?
Thanks for any hints!
Regards,
Mark






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
What is more efficient Brad Excel Discussion (Misc queries) 2 November 20th 06 09:13 PM
Is there a more efficient way to do this? Steve Roberts Excel Programming 1 September 26th 05 05:34 PM
is there a more efficient formula than... Wazooli Excel Worksheet Functions 6 February 24th 05 06:39 PM
More efficient way? Steph[_3_] Excel Programming 6 June 23rd 04 09:34 PM
Which is more efficient? Norm[_5_] Excel Programming 3 April 2nd 04 04:24 PM


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