Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: excel to array, perform functions to convert units of measure then save xls

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61824
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: excel to array, perform functions to convert units of measure then save xls
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 [3] 4   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: excel to array, perform functions to convert units ... - 6/30/2008 10:21:16 PM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi chriswebb18,

(1) To get rid of the spurious rows/records after row 3059, I used the
   clipboard to copy the range 1:A to 3059:AB to a new sheet named work

(2) based on your code lines:

       objSheet.Cells(intRow, 30).Value = intTotal1
       objSheet.Cells(intRow, 29).Value = intTotal

   I added to colums AC = Total and AD = Total1

(3) To make it easier to reference specific rows, I added a column
   AE = Recno and filled it with consecutive numbers 2..3059.

(4) Using Ctrl+Pos1 resp. Ctrl+End, I verified that Excel agrees with
   me about the number of valid records/rows

(5) Using this SQL-Script


      

    and a bit of manual editing, I came up with this table:


      

   it shows:

   (a) all cells of the columns [old whse], [Old Description], [Lawson UOM], [Lot-Code],
       [lawson Amount(soh)], [CS Amount(soh)] (, and [Recno] of course) contain not null/
       non empty data. that looks good.

   (b) the columns [Old Des# #2], [lawson Net Package], and [lawson Package SOH Qty]
       may have missing data

   (c) the empties in columns like [Old-Prod-Code] may or may not be fatal; that's for you to
       decide

   Please check/update/comment my assumptions about the fill/overwrite actions. Is it really a
   good idea to overwrite a column ([CS Amount(soh)]). Or did I misunderstand your code?

(6) Based on your code:

       If arrExcelData(9) = "EA" Then
          ...
       ElseIf arrExcelData(9) = "PA" Then
          ...
       ElseIf  arrExcelData(9) = "CT" Then
          ...
       ElseIf arrExcelData(9) = "TK" Then
          ...
       End If

    and:

       If arrExcelData(9) = "EA" And arrExcelData(14) = "E" Then
          ...
       ElseIf arrExcelData(9) = "GR" And arrExcelData(14) = "G" Then
          ...

    I assume that (the content of) [Lawson UOM] and [CS UOM ] determine, how
    to do the updates. Using this code in the sql script:


      

    I got this:


      

    The first tables shows, that [Lawson UOM] is ok: all 3058 cells contain values.
    The second one proves: [CS UOM ] contains 108 empties (2950 + 108 = 3058). I'd
    think that this is a problem. Code like

       If     ... And [CS UOM ] = "..." Then
       ElseIf ... And [CS UOM ] = "..." Then
       ...
       End If

    won't touch those 108 rows. What do you think?

    The third table shows all combinations of [Lawson UOM] and [CS UOM ] values. The
    rows

       EA      NULL    22
       GA      NULL    1
       LB      NULL    83
       TK      NULL    2

    reflect the 108 empties of [CS UOM ].

(7)  Do you think that using the third table and adding some comments about the updates/
    conversions would make sense:


      

(8) To get the [CS UOM ] empties, I added


      

  and got


      

  Perhaps you can check some these to determine their status/quality.

(9) Now lets start with some code to do the updates. Starting with


      

  we prove that we can loop over all our 3058 records/rows.

  Adding a select switch based on the [Lawson UOM]/[CS UOM ]-token table:


      

  (mark the catch all else "Case Else"), I verified that all
  rows/records would be handled. If you can specify which actions to
  take, we can start to put code into the Case sections.
 
That's all for now.

ehvbs

(in reply to ehvbs)
 
 
Post #: 41
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 12:16:01 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
here is what im doing exactly.  in lawson(old db) units for an item may be measured in gallons.  in cs(new db), they will be measured in pounds.  so i take

and compare 9 J lawson uom with 14 O cd uom to find out gallons to pounds.
then i calculate 17 R lawson soh (shipment on hand) in gallons and calculate to be how many units on hand in pounds (becoming 18 S cs soh)
-(there are a few that will stay the same like lb -> lb thats where 18.value = 17.value
then i change 11 L (the cost per uom) to the new cost per uom(20 U)
cs package soh is also a function of lawson package soh (sometimes a package is 25KG and no other way to sell even if uom change, sometimes is simply changed with uom im not sure exactly on thos yet)
total and total1 compare whther the calculations were right and show the total value of the inventory before and after calculations. (to compare i would simply use autosum in excel)


      


EDIT - so using your above code, i would insert the second bit within the loop and perform calculations under each "case" line?  and yes cs soh should be null going in, then overwrite after we get correct values.

< Message edited by chriswebb18 -- 7/1/2008 12:20:57 AM >

(in reply to ehvbs)
 
 
Post #: 42
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 12:23:44 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
on a side note, i dont believe this will work using the script the way i have as it is not that the info cannot be stored as a variable but it cannot read excel cell with that decimal information(i think).  i tweaked my script and redid in vba, then dimmed all ints as singles.  when i try to display the singles after they are set to a cell with a real number, they show blank... ado/sql may be the only way to go.  

(in reply to chriswebb18)
 
 
Post #: 43
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 12:29:57 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Did you follow the steps of my last posting? And please use the names from the table; I
don't understand your shortcuts.

< Message edited by ehvbs -- 7/1/2008 12:31:05 AM >

(in reply to chriswebb18)
 
 
Post #: 44
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 12:39:06 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Your

so using your above code, i would insert the second bit within the loop and perform calculations under each "case" line? 

==> yes; in principle, after we solved all other problems


and yes cs soh should be null going in, then overwrite after we get correct values.

==> what exactly is "cs soh"? I pointed out problems with "[CS UOM ] contains 108 empties (2950 + 108 = 3058)"
        and asked about overwriting "Is it really a
         good idea to overwrite a column ([CS Amount(soh)]). Or did I misunderstand your code? "

(in reply to ehvbs)
 
 
Post #: 45
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 1:02:11 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
pertaining to cs uom -> there are some items that we do not have any units or measure for the new (cs) database.  those we can leave or modify, it wont matter.  they are going to manually change them later.

pertaining to cs amount(soh) -> that is the number of units we currently have on hand (shipment on hand).  the input should be all empty in that column.  it is necessary to have that column filled after the conversion.  say we have 100 lb of something in lawson the lawson amount(soh) is 100.  we convert to kg (100 / 55.1150 * 25) and the cs amount(soh) would be 45.3957... then i convert the cost per uom(per lb to per kg) and make sure that when we multiply our lawson cost per uom * lawson amount(soh) = cs cost per uom * cs amount(soh) is the same.  thats where total and total1 come in.   hope i made that clear

do i need to put the "if...end if"  after each case, or do the "case"'s work as the conditional ie


      

or


      

< Message edited by chriswebb18 -- 7/1/2008 1:06:32 AM >

(in reply to ehvbs)
 
 
Post #: 46
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 1:31:22 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
Do Until "" = objSheet.Cells( iRow, [Recno] )


how does this work?  it keeps stopping at row 2 rec 0 where do you pull [recno] from?  or what does recno represent

(in reply to chriswebb18)
 
 
Post #: 47
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 1:34:05 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Instead of this:

  Case "CT-E"    '      CT      E               1
  If  arrExcelData(9) = "CT" Then
      sngNewSOH = 0
      sngNewSOH = arrExcelData(17) * arrExcelData(13)
      objSheet.Cells(sngRow, 24).Value = arrExcelData(22)
      objSheet.Cells(sngRow, 19).Value = sngNewSOH
  End If

we should have something like:

Case "CT-E"    '      CT      E               1 *** explanation of what CT combined with E means (and a hint why this combo occurs just once)
     objSheet.Cells(iRow, [decent  name from the list]).Value = some expression, perhaps refering to objSheet.Cells(iRow, [other decent  name from the list]).Value
     ...
   End If

I don't know about you, but I won't use any arrays.

After your

pertaining to cs uom -> there are some items that we do not have any units or measure for the new (cs)
database.  those we can leave or modify, it wont matter.  they are going to manually change them later.

at least the cases for the [CS UOM ] = Null are easy:

  Case "EA-NULL" '      EA      NULL           22 ** [CS UOM ] is empty; must be updated manually later
     ' nothing to be done ....

(in reply to chriswebb18)
 
 
Post #: 48
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 1:42:20 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
ad [Recno]:

(9) in my step by step guide:

Option Explicit

Const [Recno]          = 31   ' <<<<<<<<<<<<<<<

This const list will have to be updated for all the columns we use in the code:

The  "Sekect" version of the script needs

Const [Lawson UOM]     = 10
Const [CS UOM ]        = 15
Const [Recno]          = 31

A complete list of consts would look like:

Const [Facility]              =  1
Const [Tag-ID]                =  2
Const [old whse]              =  3
Const [Old-Prod-Code]         =  4
Const [Prod-Pkg-Code]         =  5
Const [CS PROD NAME]          =  6
Const [CS PROD DESC]          =  7
Const [Old Description]       =  8
Const [Old Des# #2]           =  9
Const [Lawson UOM]            = 10
Const [Lot-Code]              = 11
Const [Lawson Cost per UOM ]  = 12
Const [Product Code]          = 13
Const [CS Measure]            = 14
Const [CS UOM ]               = 15
Const [Location]              = 16
Const [Serial-Number]         = 17
Const [lawson Amount(soh)]    = 18
Const [CS Amount(soh)]        = 19
Const [Spacific Gravity]      = 20
Const [CS cost per uom]       = 21
Const [lawson Net Package]    = 22
Const [lawson Package SOH Qty]= 23
Const [CS Package SOH Qty]    = 24
Const [Package-Override]      = 25
Const [Override-Pkgs]         = 26
Const [Remarks]               = 27
Const [PlaceHolder]           = 28
Const [Total]                 = 29
Const [Total1]                = 30
Const [Recno]                 = 31

(in reply to ehvbs)
 
 
Post #: 49
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 1:57:44 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
ok, so im goig to put this into that format, but still the issue with real numbers... even when i try to perform calculations directly as so: objsheet.cells(w,x) = objsheet.cells(y,z).value / a * b  i get a null answer if there are real numbers. 

(in reply to ehvbs)
 
 
Post #: 50
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 2:18:36 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
this is what i used to change to start getting rid of the array.  then i will simply move the conditionals to the new "CASE" structure.  and i changed recno to a field that is complete all the way down.  so this way instead of numbers, it uses the name of the field if i understand right


      

(in reply to chriswebb18)
 
 
Post #: 51
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 2:20:15 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Is there any chance of locale/regional settings problems? Did you use step 5 to generate
the Fields table? Did you check whether the columns you want to compute with are of data
type 5 (double)? Did you check the cell/column format in Excel?

I have no problems with the second .xls you sent to me.

(in reply to chriswebb18)
 
 
Post #: 52
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 2:23:08 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
ad your new code: I don't understand why you can't use the code I posted. But you are
the boss: if you want to use your code, post it.

(in reply to ehvbs)
 
 
Post #: 53
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 2:33:59 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
ok i have not tested it in your new format.  i am trying to get everything so that it is formatted to work with your structur (ie no array and irow, [ ] instead of arrexceldata and sngrow, #)  i am going to pull it all over now(i am trying to avoid having to rewrite all my conditionals.)  i just hadnt seen where in your code it was changed to handle the real numbers. ill let you know once its moved and tested.  And thanks for all your help.  i know youve spent a lot of time helping me and explained things to me so i understand.  hopefully i wont need as much help next time now

(in reply to ehvbs)
 
 
Post #: 54
 
 RE: excel to array, perform functions to convert units ... - 7/1/2008 2:45:52 AM