Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 13th, 2009, 11:45 PM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Unhappy help, this VBA need run 2hours~~ ><

Sub GetCCC()
Dim rng As Range
Dim cell As Range
Dim CriteriaRng As Range
Dim calcmode As Long
Dim intK As Long
Dim intJ As Long
Dim LastRow As Long
Dim found As Boolean
Dim intI As Long
Dim bol As Boolean
Dim var As String
Dim varint As Long

intI = 2

'With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
' End With
With Sheets("Data")
Set CriteriaRng = .Range("C2", .Cells(Rows.Count, "A").End(xlUp))
End With

Sheets("CIF").Activate
LastRow = [A65536].End(xlUp).Row
'Loop through the cells in the Criteria range
For Each cell In CriteriaRng


For intK = 2 To LastRow And found <> True
With Sheets("CIF").Cells(intK, "A")
If Not IsError(.Value) Then
var = Sheets("CIF").Cells(intK, "A").Value
varint = Right(var, 7)

If varint = cell.Value Then
Sheets("Data").Cells(intI, "H").Value = Sheets("CIF").Cell(intK,"B").Value
intI = intI + 1
Exit For
End If
End If
End With
DoEvents
Next
DoEvents



Next cell

With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
End Sub





above is the code i wrote.
can some1 help me to simplify this code?
because its really run very slow.
for the sheet("CIF"), there are 19k++ records to loop through, and for the sheet("data")
there are 2k++ records also. which mean the system need run 2K * 19K of records...
>< can any1 help me? i really desperate to solve this prob...

thousand thanks in advance
regards,
kysonMok
 
Old May 14th, 2009, 01:09 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

There are some you cad do away with

1. DoEvents - you can remove them.

2. Use Cells.Find to find the text you want rather than looping through the entire range of cells

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old May 14th, 2009, 01:38 AM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Shasur View Post
Hi

There are some you cad do away with

1. DoEvents - you can remove them.

2. Use Cells.Find to find the text you want rather than looping through the entire range of cells

Cheers
Shasur

tq for reply, but how to use cells?
because the number of records mayb different.
thanks agian..

regards,
kysonMok
 
Old May 14th, 2009, 02:08 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Here is a hint

var = Sheets("CIF").Cells(intK, "A").Value
varint = Right(var, 7)
Dim rFnd As Range
Set rFnd = Sheets("CIF").Range("A:A").Find(What:=varint, lookat:=xlPart, LookIn:=xlValues)
If Not rFnd Is Nothing Then

End If
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
The Following User Says Thank You to Shasur For This Useful Post:
kysonMok (May 14th, 2009)
 
Old May 22nd, 2009, 04:44 AM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Shasur View Post
Here is a hint

var = Sheets("CIF").Cells(intK, "A").Value
varint = Right(var, 7)
Dim rFnd As Range
Set rFnd = Sheets("CIF").Range("A:A").Find(What:=varint, lookat:=xlPart, LookIn:=xlValues)
If Not rFnd Is Nothing Then

End If
thanks agian, but rather than using excel to loop through all the records,
i decided to switch to ms access, which is faster, then just import back the file into excel.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM
<STRONG> vs <B> and <EM> vs <I> anshul HTML Code Clinic 12 September 1st, 2004 05:22 PM
a problem in book<<beginning asp.net using vb>> luoware ASP.NET 1.0 and 1.1 Basics 3 December 8th, 2003 09:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.