Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default HELP - Perl 'Hash' Functionality Required In VBA

Hi,
I am new to VBA programming but understand a little of Perl, I am
trying to read the contents of all Excel worksheets within a workbook
and then summarise this data on a seperate worksheet, a lot of the
data in the worksheets is diplicated and I do not want this
duplication appearing on the new summarised worksheet. What I was
hoping to do was store the data in a hash table (like perl) and then
test for the existance of the key each time I added data to it or
simply just put the new key over the top as the value would be the
same as well as the key. Is there a way I can do this within VBA and
if possible give me an example..

many thanks, Mark.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default HELP - Perl 'Hash' Functionality Required In VBA

Basic is not a great language for building Hash tables. C Language is better
for building has tables because of the pointers in C Language.

Hash Table are good if you have a lot of data and ae trying to speed up the
algorithm. It also requires lots of memory (if your table is large).

First try the simplier method with excel. Put each piece of data on a new
wroksheet and check to make usre the data isn't on the new worksheet before
putting the new data. A simple find works quickly and should do the job.


CheckData = "abc"
set c = worksheet("new").columns("A").find(what:=Checkdata , _
lookin:=xlvalues,lookat:=xlwhole)
if not c is nothing then

' enter your code
else
msgbox("Could not find : " & CheckData)
end if





"tommo_blade" wrote:

Hi,
I am new to VBA programming but understand a little of Perl, I am
trying to read the contents of all Excel worksheets within a workbook
and then summarise this data on a seperate worksheet, a lot of the
data in the worksheets is diplicated and I do not want this
duplication appearing on the new summarised worksheet. What I was
hoping to do was store the data in a hash table (like perl) and then
test for the existance of the key each time I added data to it or
simply just put the new key over the top as the value would be the
same as well as the key. Is there a way I can do this within VBA and
if possible give me an example..

many thanks, Mark.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default HELP - Perl 'Hash' Functionality Required In VBA

thanks, that has worked a treat :-)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default HELP - Perl 'Hash' Functionality Required In VBA

You can use a Scripting Dictionary for this. It's close enough to a hash
table.

http://www.4guysfromrolla.com/webtech/102898-1.shtml

Tim

"tommo_blade" wrote in message
...
Hi,
I am new to VBA programming but understand a little of Perl, I am
trying to read the contents of all Excel worksheets within a workbook
and then summarise this data on a seperate worksheet, a lot of the
data in the worksheets is diplicated and I do not want this
duplication appearing on the new summarised worksheet. What I was
hoping to do was store the data in a hash table (like perl) and then
test for the existance of the key each time I added data to it or
simply just put the new key over the top as the value would be the
same as well as the key. Is there a way I can do this within VBA and
if possible give me an example..

many thanks, Mark.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default HELP - Perl 'Hash' Functionality Required In VBA

just to expand on the 'find' method which worked ok for me, can
someone tell me how I can recall the row & column number when the find
is succesfull, the code I am using is detailed below:

CheckData = "abc"
set c = worksheet("sheet 1").columns("A").find(what:=Checkdata, _
lookin:=xlvalues,lookat:=xlwhole)
if not c is nothing then


msgbox "Found the data: " & Checkdata"
else
msgbox "Could not find : " & CheckData
end if



cheers.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default HELP - Perl 'Hash' Functionality Required In VBA

c.Row
c.Column

Tim

"tommo_blade" wrote in message
...
just to expand on the 'find' method which worked ok for me, can
someone tell me how I can recall the row & column number when the find
is succesfull, the code I am using is detailed below:

CheckData = "abc"
set c = worksheet("sheet 1").columns("A").find(what:=Checkdata, _
lookin:=xlvalues,lookat:=xlwhole)
if not c is nothing then


msgbox "Found the data: " & Checkdata"
else
msgbox "Could not find : " & CheckData
end if



cheers.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default HELP - Perl 'Hash' Functionality Required In VBA

thanks that seems to have done the trick but I have another issue now
that I cannot understand, I am getting the error 'next without for' in
the following code, can anyone see the issue, I have highlighted the
problem 'next' statements with a '=' prior to the statement - can you
not have more than one next statement for a single 'for' statement - i
just want the code to skip to the next in the loop once those
conditions are met ?

-----------------------------------------------------------------------------------------------------------------------------------------
For z = 1 To 1000
If ActiveSheet.Cells(z, 1) < "" Then
MyData = Split(ActiveSheet.Cells(z, 1), ":")
player = MyData(2)
club = MyData(1)
position = MyData(0)
Else
'msgbox "EMPTY CELL B"

=Next z

End If

If ActiveSheet.Cells(z, 2) < "N" Then
goals_scored = ActiveSheet.Cells(z, 2)
MsgBox "MATCH DATA FOUND: " & player & " GOAL SCORED: " &
goals_scored
Else
'MsgBox "NO MATCH DATA FOR: " & player

=Next z

End If

For x = 1 To Worksheets.Count
If InStr(1, Worksheets(x).Cells(1, 1), "Team Name") = 1 Then
MsgBox "WORKSHEET: " & Worksheets(x).Name & "Looking
for PLAYER:" & player
Set f = Worksheets(x).Columns("B").Find(what:=player,
LookIn:=xlValues, lookat:=xlWhole)
If Not f Is Nothing Then
MsgBox player & " FOUND IN ROW " & f.row
Worksheets(x).Cells(f.row, col) = goals_scored
'MsgBox player & " FOUND IN ROW " & f.row &
"UPDATING DATA: " & f.row & f.col & goals_scored
Else
MsgBox player & "FOUND NOT FOUND ON WORKSHEET:" &
Worksheets(x).Name
End If
'Next x
End If
Next x

Next z

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

thanks, Mark.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default HELP - Perl 'Hash' Functionality Required In VBA

try changing

'MsgBox "NO MATCH DATA FOR: " & player
=Next z
End If
to

'MsgBox "NO MATCH DATA FOR: " & player
End If
=Next z


Cliff Edwards
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default HELP - Perl 'Hash' Functionality Required In VBA

if i change that as you state then it complains about the 1st '=next
z' statement, i.e.

'msgbox "EMPTY CELL B"

=Next z

End If

if I also modify this part of the code so the 'next z' follows the
'end if' then the warning I get reverts back to the original 'next z'
statement for which you have already commented upon.

I take it that I can have multiple next statement within a single for
loop ?

cheers.



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default HELP - Perl 'Hash' Functionality Required In VBA

You have to nest the ifs completely between the fors and nexts and you
can only have one next for each for. (afaik)You'll have to nest an if
in an if to test for two conditions.

Cliff Edwards



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default HELP - Perl 'Hash' Functionality Required In VBA

Maybe something like this -

For z = 1 To 1000
If ActiveSheet.Cells(z, 1) < "" Then
MyData = Split(ActiveSheet.Cells(z, 1), ":")
player = MyData(2)
club = MyData(1)
Position = MyData(0)
If ActiveSheet.Cells(z, 2) < "N" Then
goals_scored = ActiveSheet.Cells(z, 2)
MsgBox "MATCH DATA FOUND: " & player & " GOAL SCORED: " &
goals_scored
For x = 1 To Worksheets.Count
If InStr(1, Worksheets(x).Cells(1, 1), "Team Name") = 1
Then
MsgBox "WORKSHEET: " & Worksheets(x).Name & "Looking
for PLAYER:" & player
Set f = Worksheets(x).Columns("B").Find(what:=player,
LookIn:=xlValues, lookat:=xlWhole)
If Not f Is Nothing Then
MsgBox player & " FOUND IN ROW " & f.Row
Worksheets(x).Cells(f.Row, col) = goals_scored
MsgBox player & " FOUND IN ROW " & f.Row & "UPDATING
DATA: " & f.Row & f.col & goals_scored
Else
MsgBox player & "FOUND NOT FOUND ON WORKSHEET:" &
Worksheets(x).Name
End If
End If
Next x
End If
End If
Next z

I didn't test it, but I think the structures are right.

Cliff Edwards
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default HELP - Perl 'Hash' Functionality Required In VBA

worked a treat, many thanks for this :-)

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 the perl table ??? and how i can use this sunil sharma New Users to Excel 0 May 8th 08 09:39 AM
Convert prl (Perl?) to xls or csv Steve Excel Discussion (Misc queries) 0 March 3rd 08 03:07 PM
Extra functionality required Hilton Excel Discussion (Misc queries) 5 October 4th 07 08:59 AM
Assistance with VB Coding in excel required for Telnet and FTP functionality Clinton M James[_2_] Excel Programming 0 February 26th 07 12:35 PM
link to Perl/Java Dave F[_5_] Excel Programming 1 January 28th 04 03:01 PM


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