D
Dennis
Below is a snippet of an Excel VBA Macro that I converted to VB6. The code
executes almost instantly in Excel while it takes VB6 36seconds. I've excluded
all the Dim statements for brevity. There are no variant variables. All the
Cell indices are defined in the sub ColumnNumber. I've added the "Microsoft
Excel 9.0 Object Library" to the project References.
Any Ideas?
Thanks.
Dennis
==========VB6 Code ========================================
Option Explicit
Public XL As Excel.Application 'Make Global for other subroutines to use
Sub main()
Set XL = New Excel.Application
XL.Workbooks.Open Filename:="c:\myExcelFile.csv"
With XL.ActiveWorkbook
With .Sheets(1)
'Find Column numbers for given column labels
ColumnNumber
If (iont = 0 Or iosnp = 0) Then
MsgBox (" iont=" & iont & " iosnp=" & iosnp )
Exit Sub
End If
LastRow = .Cells(Rows.Count, "a").End(xlUp).Row
LastCol = .Range("A1").End(xlToRight).Column
For irow = 2 To LastRow 'first row is labels
avOSNP = 0
osnp = .Cells(irow, iosnp).Value
ont = .Cells(irow, iont).Value
If ont = 0 Then ont = 1
If ont = -1 Then ont = 1
If ont > 0 Then avOSNP = osnp / ont
'replace osnp with avosnp
.Cells(irow, iosnp).Value = avOSNP
'Adjust r22 and r2 for negative slopes
slope = .Cells(irow, ib0).Value
r2 = .Cells(irow, ir2).Value
r22 = .Cells(irow, ir22).Value
If slope < 0 Then
If r2 > 0 Then .Cells(irow, ir2).Value = -r2
If r22 > 0 Then .Cells(irow, ir22).Value = -r22
End If
Next irow
End With '.Sheets(1)
End With 'XL.ActiveWorkbook
End Sub
executes almost instantly in Excel while it takes VB6 36seconds. I've excluded
all the Dim statements for brevity. There are no variant variables. All the
Cell indices are defined in the sub ColumnNumber. I've added the "Microsoft
Excel 9.0 Object Library" to the project References.
Any Ideas?
Thanks.
Dennis
==========VB6 Code ========================================
Option Explicit
Public XL As Excel.Application 'Make Global for other subroutines to use
Sub main()
Set XL = New Excel.Application
XL.Workbooks.Open Filename:="c:\myExcelFile.csv"
With XL.ActiveWorkbook
With .Sheets(1)
'Find Column numbers for given column labels
ColumnNumber
If (iont = 0 Or iosnp = 0) Then
MsgBox (" iont=" & iont & " iosnp=" & iosnp )
Exit Sub
End If
LastRow = .Cells(Rows.Count, "a").End(xlUp).Row
LastCol = .Range("A1").End(xlToRight).Column
For irow = 2 To LastRow 'first row is labels
avOSNP = 0
osnp = .Cells(irow, iosnp).Value
ont = .Cells(irow, iont).Value
If ont = 0 Then ont = 1
If ont = -1 Then ont = 1
If ont > 0 Then avOSNP = osnp / ont
'replace osnp with avosnp
.Cells(irow, iosnp).Value = avOSNP
'Adjust r22 and r2 for negative slopes
slope = .Cells(irow, ib0).Value
r2 = .Cells(irow, ir2).Value
r22 = .Cells(irow, ir22).Value
If slope < 0 Then
If r2 > 0 Then .Cells(irow, ir2).Value = -r2
If r22 > 0 Then .Cells(irow, ir22).Value = -r22
End If
Next irow
End With '.Sheets(1)
End With 'XL.ActiveWorkbook
End Sub