Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Excel vbscript help

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Excel vbscript help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Excel vbscript help - 7/20/2008 3:04:32 AM   
  gcdisciple

 

Posts: 3
Score: 0
Joined: 7/8/2008
Status: offline
Hi guys, I've got an issue with a vbscript program i'm writing.  Its supposed to open up one file, perform a calculation on every field (Multiplying by .15 rounding up and then multiplying it by .1), then switch to another excel spreadsheet and use the information from the first to do a few more calculations before setting the result in the 2nd spreadsheets cell.  Each spreadsheet has multiple tabs that I will need to switch to and then perform the calculations all over again.  Right now I've gotten it to to do the first part in a single spreadsheet and checked that it works.  However, trying to open up the 2nd one is causing problems.  It will run and it won't throw an error or give me a sucess message.  I also think that the error handling or lack therof is an issue.  Each spreadsheet has text in some cells and I was unable to sucessfully implement a check to makes sure it was only numeric.  As a result I think it might be screwing up some of the results.  Any help is greatly appreciated I'm kind of lost at the moment.. 

Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.WorkBooks.Open("C:\1.xls")
Set objWB2 = objXL.WorkBooks.Open("C:\2.xls")
'wohoo for lazy variable naming
dim value1
DIm value2
dim total
dim total2
dim startcol
dim endcol
dim startrow
dim endrow
Function Roundme(x)
If Int(x) <> x Then
Roundme = Fix(x) + Sgn(x)
else
end if
End Function
' Variables to Change per file
'Starting and Ending Columns
startcol=1
endcol=10
'1st Starting and Ending Rows
startrow=1
endrow=62
dim i
for a = startcol to endcol
For i = startrow To endrow
On Error Resume Next
if IsNumeric(objXL.cells(i,a)) and Len(Trim(objXL.cells(i,a))) > 0 Then
value1=Roundme((objXL.cells(i,a) * .15))
value2=Roundme((objXL.cells(i,a) * .1))
total = value1+value2
total2 = objXL2.cells(i,a)+75
total2 = total2 + total
objXL2.cells(i,a) = total2
Else
end if
next
next
objWB.Close
objXL.Quit
objWB2.Close
 
 
Post #: 1
 
 RE: Excel vbscript help - 7/25/2008 1:58:07 AM   
  mcds99


Posts: 434
Score: 4
Joined: 2/28/2006
Status: offline
Excel is picky about how you use it.

You need to define both files.


      






_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to gcdisciple)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Excel vbscript help Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts