Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Quick VBA method for looking up data

Hello All,

I was wondering if it is possible to have some VBA code read a file of
data and then find each item in an excel sheet a paste a value into a
given cell. I currently do this by defining the source range and the
destination range. Then for each account in the destination range I
check if it was in the source range and if it was then I paste the
required value in a cell offset from the account number. The problem
with this is that it is quite slow and the VBA Module is continually
reading the data to find matches. Is there a way for the VBA to read
the entire source range to memory and then check for each account in
the destination range (they may no longer exist in the destination
data) and paste the value required? I have posted my current code
below.

Sub Match()
Dim CCRange As Range 'Define the destination range
Dim MSRange As Range 'Define the source data range
Dim CCAccount As Range
Dim MSAccount As Range


Set CCRange = FindRange(CCWorkbook.Worksheets("Cap Completions"),
"a8")
Set MSRange = FindRange(MSWorkbook.Worksheets("funding move"), "A1")

For Each MSAccount In MSRange 'Begin loop
Debug.Print MSAccount.Address
If MSAccount.Value < "" Then 'Check for account on current line
For Each CCAccount In CCRange
If MSAccount.Value = CCAccount.Value Then
CCAccount.Offset(, 15).Value = "NU" 'Offset destination
account
End If
Next CCAccount
End If
Next MSAccount

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Quick VBA method for looking up data

I don't know how CCRange and MSRange get set, but if CCRange is one column, you
could use application.match:

Option Explicit
Sub match()

'add a declare
Dim res As Variant
Dim CCRange As Range 'Define the destination range
Dim MSRange As Range 'Define the source data range
Dim CCAccount As Range
Dim MSAccount As Range

Set CCRange = FindRange(CCWorkbook.Worksheets("Cap Completions"), "a8")
Set MSRange = FindRange(MSWorkbook.Worksheets("funding move"), "A1")

For Each MSAccount In MSRange
res = Application.match(MSAccount.Value, CCRange, 0)
If IsError(res) Then
'no match found
Else
CCRange(res).Offset(0, 15).Value = "NU"
End If
Next MSAccount

End Sub



Richard wrote:

Hello All,

I was wondering if it is possible to have some VBA code read a file of
data and then find each item in an excel sheet a paste a value into a
given cell. I currently do this by defining the source range and the
destination range. Then for each account in the destination range I
check if it was in the source range and if it was then I paste the
required value in a cell offset from the account number. The problem
with this is that it is quite slow and the VBA Module is continually
reading the data to find matches. Is there a way for the VBA to read
the entire source range to memory and then check for each account in
the destination range (they may no longer exist in the destination
data) and paste the value required? I have posted my current code
below.

Sub Match()
Dim CCRange As Range 'Define the destination range
Dim MSRange As Range 'Define the source data range
Dim CCAccount As Range
Dim MSAccount As Range


Set CCRange = FindRange(CCWorkbook.Worksheets("Cap Completions"),
"a8")
Set MSRange = FindRange(MSWorkbook.Worksheets("funding move"), "A1")

For Each MSAccount In MSRange 'Begin loop
Debug.Print MSAccount.Address
If MSAccount.Value < "" Then 'Check for account on current line
For Each CCAccount In CCRange
If MSAccount.Value = CCAccount.Value Then
CCAccount.Offset(, 15).Value = "NU" 'Offset destination
account
End If
Next CCAccount
End If
Next MSAccount

End Sub


--

Dave Peterson

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
Method for protecting cells which still allows quick editing rbart3 Excel Discussion (Misc queries) 2 December 4th 09 04:24 PM
Quick lookup for data Max Excel Worksheet Functions 1 April 12th 09 08:50 PM
Please post this thread a correct full method, method about Nast Runsome New Users to Excel 8 February 25th 08 03:29 PM
Please post this thread a complete correct method, method about te Nast Runsome New Users to Excel 0 February 23rd 08 09:42 PM
Quick method to add absolute references in Excel using keyboard photon63 Excel Discussion (Misc queries) 2 February 11th 05 08:27 AM


All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"