Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Attempting a dynamically defined conditional in VBA

Greetings,

I am attempting to create a general purpose data extraction utility, which
can extract the contents of one Excel worksheet & copy it into user-defined
columns in another worksheet.

Example:
SOURCE COLUMN ACTION/CRITERIA DESTINATION COLUMN
------------------------------------------------------------------------------------
A EQUALS A
D SHALL BE COPIED TO C

The above would be the interface on the Excel worksheet. The user specifies
the source and destination files via a browse window. The script would then
perform the task of iterating through the rows of the source worksheet,
finding each instance where the source worksheet's 'A' column value matches
the value in an 'A' column of the destination worksheet. When such an
instance is found, it then performs the task of copying the contents of the
current row of Column 'D' from the source worksheet, to Column 'C' of the
matching row in the destination worksheet. All possible criteria that could
be entered into the Action/Criteria cell a EQUALS, CONTAINS, BEGINS WITH,
ENDS WITH, SHALL BE COPIED OVER TO. A dropbox is used for the
Action/Criteria Cell, to prevent erroneous data entry.

I'm already set with coding the actual finding & copying operations. What I
need assistance on (if it is possible), is how to dynamically generate
conditional statements in VBA. By this I mean:

Dim sourcecol as string
Dim actcrit as string
Dim destcol as string

' User enters the info given in the example above, so that the following
' conditional statement (?) can be exercised in the code

If sourcecol(1) & actcrit(1) & destcol(1) Then 'If Src A = Dest A
DESTFILE & destcol(2) = SRCFILE & srccol(2)
End if

I know that I could simply have a case statement or nested if to "find" the
correct operation(s) to perform, but that would be a HUGE set of possible
permutations of criteria (even at a maximum of 5 criteria).

This needs to be an automated process that could potentially have up to 5
criteria (conditions to look for) before performing the operation & may deal
with multiple files (sequentially) from other users. Therefore, using
worksheet functions will not suffice.

Any help with this would be most appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Attempting a dynamically defined conditional in VBA

I've only skim read your post but I think the Evaluate method should
help you.

This will perform a calculation based on a string input, eg.
If Evaluate(sourcecol(1) & actcrit(1) & destcol(1)) Then
....

Best regards,
Andrew


On 28 Sep, 15:45, Garbunkel
wrote:
Greetings,

I am attempting to create a general purpose data extraction utility, which
can extract the contents of one Excel worksheet & copy it into user-defined
columns in another worksheet.

Example:
SOURCE COLUMN * * * * *ACTION/CRITERIA * * * * *DESTINATION COLUMN
---------------------------------------------------------------------------*---------
A * * * * * * * * * * * * * * * * EQUALS * * * * * * * * * * * * A
D * * * * * * * * * * * * * * * * SHALL BE COPIED TO * * *C

The above would be the interface on the Excel worksheet. *The user specifies
the source and destination files via a browse window. *The script would then
perform the task of iterating through the rows of the source worksheet,
finding each instance where the source worksheet's 'A' column value matches
the value in an 'A' column of the destination worksheet. *When such an
instance is found, it then performs the task of copying the contents of the
current row of Column 'D' from the source worksheet, to Column 'C' of the
matching row in the destination worksheet. *All possible criteria that could
be entered into the Action/Criteria cell a EQUALS, CONTAINS, BEGINS WITH,
ENDS WITH, SHALL BE COPIED OVER TO. *A dropbox is used for the
Action/Criteria Cell, to prevent erroneous data entry.

I'm already set with coding the actual finding & copying operations. *What I
need assistance on (if it is possible), is how to dynamically generate
conditional statements in VBA. *By this I mean:

Dim sourcecol as string
Dim actcrit as string
Dim destcol as string

' User enters the info given in the example above, so that the following
' conditional statement (?) can be exercised in the code

If sourcecol(1) & actcrit(1) & destcol(1) Then * * * 'If Src A = Dest A
* * * DESTFILE & destcol(2) = SRCFILE & srccol(2)
End if

I know that I could simply have a case statement or nested if to "find" the
correct operation(s) to perform, but that would be a HUGE set of possible
permutations of criteria (even at a maximum of 5 criteria).

This needs to be an automated process that could potentially have up to 5
criteria (conditions to look for) before performing the operation & may deal
with multiple files (sequentially) from other users. *Therefore, using
worksheet functions will not suffice. *

Any help with this would be most appreciated!


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
Sum a dynamically-defined range Hershmab Excel Discussion (Misc queries) 3 December 7th 09 05:14 PM
Dynamically Copying Changing Conditional Formatting sdm New Users to Excel 0 September 5th 08 05:42 PM
ComboxBox with Dynamically Defined Source, and LinkedCell error GlennUK Excel Discussion (Misc queries) 1 June 4th 08 03:11 PM
User defined - conditional between statement??? Gary F Shelton Excel Programming 1 December 21st 07 07:50 AM
Multi-conditional user defined function keysol100 Excel Programming 0 August 5th 04 07:38 PM


All times are GMT +1. The time now is 04:52 AM.

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"