Question : Excel VBA - paste value into active cell and run addin against it

Please see code below.  It has all the steps outlined in it.

basically, the goal is to paste a value from a worksheet into an another active worksheet and run  a vba code against it.  

-it will run through an entire spreadsheet and pull all values froma given row and populate the active cell and run the addin against it.

-the loop will wiat until the addin is done with its processes

-vba will save a the data to a file

-the process will be completed and  the process will repeat...until the values in the b column are exashted...
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Option Explicit
 
Sub runLoanCBCode()
 
 On Error Resume Next
   
  Dim wb As Workbook, ws As Worksheet
  Dim cell As Range, count As Integer
  Dim outputLnNumber As String
  Dim inputLnNumber As String
  Dim rw As String
  Dim myPath  As String
  Dim CBFileSysOutput As String
  Dim Response As String
 
  rw = 5
  Set wb = Application.Workbooks("Foreclosure Tree.xlsx")
  Set ws = Worksheets("Data File").Activate
  count = 0
  
  Application.StatusBar = True
    
  CBFileSysOutput = "C:\CBReportingDocLoan2009" & "\" & outputLnNumber & ".cbr"
  
  'need to activate the sheet first
  'Create object of Crystal Ball
  'Create object of spreadsheet with the loan number
  'create object of spreadsheet with the loan numbers for EOF
  'Create a directory to save new copy of CB to
  myPath = "C:\CBReportingDocLoan2009"
  If Dir$(myPath, vbDirectory) = "" Then MkDir myPath
 
   'run the loop
  For Each cell In ws.Range("B5", ws.Range("B863").End(xlUp))
    '1. pull the loan number from the data file inside of workbook -->set in DB format; all loan #'s
    'Get cell data
    cell.Value = outputLnNumber
  
    '2. insert the loan number into the cell
    Application.Workbooks("Foreclosure Tree.xlsx").Worksheets("Model").Activate
    Range("loan_num").Value = outputLnNumber
   
    '3.start the CB, run the addin from here
     'Application.Run (Application.Workbooks("Foreclosure Tree.xlsx").Worksheets("Model"))
     'Application.Workbooks("Foreclosure Tree.xlsx").Worksheets("Model").Activate = CB.Startup()
     
      Response = MsgBox("Click OK to run Crystal Ball")
     'Make sure that we reset the simulation trial back to 1
     CB.ResetND
     
     'Now lets the run the simulation after the vlaue has been inputed in the loan_num cell
     CB.Simulation 1000
     
    
    '4.wait until done
    
        If Dir(CBFileSysOutput) = "" Then
         DoEvents
        Else
         Application.Workbooks("Foreclosure Tree.xlsx").Worksheets("Model").Activate = CB.shutdown()
        End If
           
    '5. Capture the results in Excel Sheet
    '6. Repeat until the end of the file
    Application.Workbooks("Foreclosure Tree.xlsx").Worksheets("Model").Activate = CB.shutdown()
 Next cell
  Response = MsgBox("Task Complete")
End Sub

Answer : Excel VBA - paste value into active cell and run addin against it

What is the problem that you need help with?
Random Solutions  
 
programming4us programming4us