Fastest Way Through A Large Range


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

 
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12th September 2013, 20:56
nalgene5622's Avatar
nalgene5622 nalgene5622 is offline
Frequent User
MS Office Version: Ms Office 2010
MS Office Skill Level: Okay at VBA but still learning
 
Join Date: Apr 2012
Location: Austin, TX
Posts: 174
Posts Per Day: 0.09
My Top Tip Count: 0
Thanks to others: 28
Thanked 0 Times in 0 Posts
Reputation: 10 (7) nalgene5622 is on a distinguished road
Default Fastest Way Through A Large Range
     Excel: VBA   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: VBA   

What is the fastest way to go through a range?

For example I have numeric data from A1:A50000 and I want to add 3 to each value in the range. What is the fastest way to achieve this in vba.

I have seen stuff online about putting the range into an array but not sure how to do this or if it is even faster.

Any suggestions?



The Code Cage Advertisment
Advertisement
  #2  
Old 12th September 2013, 21:29
snb's Avatar
snb snb is offline
Forum VIP
MS Office Version: > Office 97
MS Office Skill Level: Interested
 
Join Date: Feb 2011
Location: Europe
Posts: 1,393
Posts Per Day: 0.56
My Top Tip Count: 0
Thanks to others: 0
Thanked 314 Times in 307 Posts
Reputation: 5076 (70) snb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond repute
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


VBA CODE:
 
Sub M_snb() 
    [A1:A50000]=[index(A1:A50000+3,)] 
End Sub 



  #3  
Old 13th September 2013, 14:30
nilem's Avatar
nilem nilem is offline
Junior Member
MS Office Version: Ms Office 2010
MS Office Skill Level: New to MS Office
 
Join Date: Jun 2012
Location: Ufa, Russia
Posts: 24
Posts Per Day: 0.01
My Top Tip Count: 0
Thanks to others: 0
Thanked 9 Times in 9 Posts
Reputation: 175 (7) nilem has a spectacular aura aboutnilem has a spectacular aura about
Russia
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


Seems it works too
VBA CODE:
Sub M_snb2() 
     '    [A1:A50000] = [index(A1:A50000+3,)]
    [A1:A50000] = [A1:A50000+3] 
End Sub 



The Code Cage Advertisment
Advertisement
  #4  
Old 13th September 2013, 17:39
nalgene5622's Avatar
nalgene5622 nalgene5622 is offline
Frequent User
MS Office Version: Ms Office 2010
MS Office Skill Level: Okay at VBA but still learning
 
Join Date: Apr 2012
Location: Austin, TX
Posts: 174
Posts Per Day: 0.09
My Top Tip Count: 0
Thanks to others: 28
Thanked 0 Times in 0 Posts
Reputation: 10 (7) nalgene5622 is on a distinguished road
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


Very Nice. Building on the question how would you say if Range A1:A50000 is equal to 5 then change all the values in Range A1:A50000 that equal 5 to the value of "test".

Basically looking through Range A1:A50000 and if a value in that range is equal to 5 then change it to "test"



  #5  
Old 13th September 2013, 18:12
snb's Avatar
snb snb is offline
Forum VIP
MS Office Version: > Office 97
MS Office Skill Level: Interested
 
Join Date: Feb 2011
Location: Europe
Posts: 1,393
Posts Per Day: 0.56
My Top Tip Count: 0
Thanks to others: 0
Thanked 314 Times in 307 Posts
Reputation: 5076 (70) snb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond repute
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


What will the next question after answering this one ?



  #6  
Old 13th September 2013, 18:26
nalgene5622's Avatar
nalgene5622 nalgene5622 is offline
Frequent User
MS Office Version: Ms Office 2010
MS Office Skill Level: Okay at VBA but still learning
 
Join Date: Apr 2012
Location: Austin, TX
Posts: 174
Posts Per Day: 0.09
My Top Tip Count: 0
Thanks to others: 28
Thanked 0 Times in 0 Posts
Reputation: 10 (7) nalgene5622 is on a distinguished road
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


None that I know of. I just realized I will need to change the values. Still trying to understand the brackets and arrays. Thanks for asking what the next question would be though.



The Code Cage Advertisment
Advertisement
  #7  
Old 14th September 2013, 02:23
Gary's Student's Avatar
Gary's Student Gary's Student is offline
Solution Centre Professional
MS Office Version: Excel 2007
MS Office Skill Level: Proficient with Excel
 
Join Date: Feb 2013
Location: Lakehurst, USA
Age: 72
Posts: 37
Posts Per Day: 0.02
My Top Tip Count: 0
Thanks to others: 2
Thanked 7 Times in 7 Posts
Reputation: 160 (6) Gary's Student has a spectacular aura aboutGary's Student has a spectacular aura about
USA
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


Perhaps something like:

VBA CODE:
Sub UseEvaluate() 
    With Range("A1:A50000") 
        .Value = Evaluate("=IF(" & .Address & "=5" & "," & """Test""" & "," & .Address & ")") 
    End With 
End Sub 



  #8  
Old 15th September 2013, 10:47
Roger Govier's Avatar
Roger Govier Roger Govier is offline
Solution Centre Professional
MS Office Version: MS Office 97, 2003, 2007, 2010, 2013
MS Office Skill Level: Proficient with Excel
 
Join Date: Jan 2009
Location: Abergavenny, Wales, UK
Posts: 222
Posts Per Day: 0.07
My Top Tip Count: 0
Thanks to others: 0
Thanked 47 Times in 47 Posts
Reputation: 985 (20) Roger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to behold
Wales
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


Hi

Maybe just

VBA CODE:
Sub Test() 
    With [a1:A50000] 
        .Replace 5, "Test" 
    End With 
End Sub 
__________________
Regards - Roger Govier, Microsoft Excel MVP



  #9  
Old 15th September 2013, 11:31
Gary's Student's Avatar
Gary's Student Gary's Student is offline
Solution Centre Professional
MS Office Version: Excel 2007
MS Office Skill Level: Proficient with Excel
 
Join Date: Feb 2013
Location: Lakehurst, USA
Age: 72
Posts: 37
Posts Per Day: 0.02
My Top Tip Count: 0
Thanks to others: 2
Thanked 7 Times in 7 Posts
Reputation: 160 (6) Gary's Student has a spectacular aura aboutGary's Student has a spectacular aura about
USA
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


Hi Roger:

So:
55
would become:
TestTest



The Code Cage Advertisment
Advertisement
  #10  
Old 15th September 2013, 11:59
Roger Govier's Avatar
Roger Govier Roger Govier is offline
Solution Centre Professional
MS Office Version: MS Office 97, 2003, 2007, 2010, 2013
MS Office Skill Level: Proficient with Excel
 
Join Date: Jan 2009
Location: Abergavenny, Wales, UK
Posts: 222
Posts Per Day: 0.07
My Top Tip Count: 0
Thanks to others: 0
Thanked 47 Times in 47 Posts
Reputation: 985 (20) Roger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to beholdRoger Govier is a splendid one to behold
Wales
Default Re: Fastest Way Through A Large Range

------ Register to get rid of these "In Post" ads! ------


Quite right Gary, very sloppy on my part.

Should be
VBA CODE:
Sub Test() 
    With [a1:A50000] 
        .Replace 5, "Test", xlWhole 
    End With 
End Sub 
__________________
Regards - Roger Govier, Microsoft Excel MVP



The Code Cage Advertisment
Advertisement
 
The Code Cage at Facebookhe Code Cage at Twitter


Tags
fastest, large, range

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 07:41.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University
X vBulletin 3.8.7 Debug Information
  • Page Generation 0.21462 seconds
  • Memory Usage 6,654KB
  • Queries Executed 15 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footerEnd
  • (1)ad_footerStart
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_headerEnd
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_leftcolumn_code
  • (1)ad_navbar_below
  • (5)ad_postbit_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (10)helpful_answers
  • (1)helpfulanswers_javascript
  • (1)navbar
  • (3)navbar_link
  • (3)navbar_noticebit
  • (52)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_ctoptip
  • (10)postbit_onlinestatus
  • (47)postbit_reputation
  • (10)postbit_wrapper
  • (1)showthread_changepostsowner_link
  • (1)showthread_extra_fields
  • (1)showthread_quickreply_mrgdp
  • (1)showthread_reason_popup
  • (1)spacer_close
  • (1)spacer_open
  • (1)su_form
  • (3)tagbit
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_datastore.php
  • ./includes/class_hook.php
  • ./awcoding/plugins/awc.php
  • ./awcoding/plugins/ds.php
  • ./awcoding/plugins/ss.php
  • ./includes/functions_notice.php
  • ./mobiquo/smartbanner.php
  • ./mobiquo/include/classTTConnection.php
  • ./mobiquo/smartbanner/head.inc.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/vbatags.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php
  • ./includes/functions_misc.php 

Hooks Called:
  • init_startup
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_check_criteria
  • notices_noticebit
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • helpfulanswers_showthreadorpost
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • helpfulanswers_show_normal
  • reputation_power
  • reputation_image
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • error_fetch
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete