Solved

Sub not calling

Posted on 2011-02-24
10
306 Views
Last Modified: 2012-05-11
I have a sub and within it i call various subs

A particular sub is not calling

Call FillFormula

if i step through the sub, it will call, if i run it all at once through a button, it does not call it.

Is there an error in my structure?

Thanks
Seamus
Sub RunReport()


        
    Workbooks.Open Filename:= _
        "G:\Asset Services MI\TLM Stock Breaks\TLM Stock_Break_Data Source.xls"
        
Call ColumnODate
Call AddDateToCognosFile
Call CopyOverCognosFile
Call TodayANDYesterday
Call DeleteRecords
Call Sorting



    Workbooks("New TLM.xls").Activate
    
Call Datacall
Call FillFormula
Call AllWorkbookPivots
Call HighlightTotals
Call FutureValues

    Columns("D:D").EntireColumn.AutoFit
    Columns("E:E").EntireColumn.AutoFit
    
Sheets("Raw Data").Visible = False
Sheets("Screen").Select

 ActiveWorkbook.UpdateLink Name:= _
        "G:\Asset Services Risk Team\TLM\Asset Services Outstanding Stock Items.xls", _
        Type:=xlExcelLinks

If Sheets("Screen").Range("L1") = "Q" Then

Call TestInsertPicture

Else

MsgBox "Report Ran, Create File"
End If
End Sub

Open in new window

0
Comment
Question by:Seamus2626
  • 4
  • 4
  • 2
10 Comments
 
LVL 24

Expert Comment

by:broomee9
ID: 34971395
Post the FillFormula procedure.

Is it in the same module, is it a function, does it have the word "Private" in front of it?
0
 

Author Comment

by:Seamus2626
ID: 34971431
Here it is broomee9
Sub FillFormula()

Dim r As Long

Sheets("Raw Data").Visible = True
Sheets("Raw Data").Select
With Sheets("Raw Data")
    r = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("N2").Formula = "=F2"
    .Range("O2").Formula = "=IF(N2<=5,""0-5"",IF(AND(N2>=6,N2<=15),""6-15"",IF(AND(N2>=16,N2<=30),""16-30"",IF(AND(N2>=31,N2<=90),""31-90"",""91+""))))"
    .Range("P2").Formula = "=VLOOKUP(H2,'Mapping Table'!$B$21:$F$40,2,0)"
    .Range("Q2").Formula = "=VLOOKUP(H2,'Mapping Table'!$B$21:$F$40,3,0)"
    .Range("R2").Formula = "=VLOOKUP(H2,'Mapping Table'!$B$21:$F$40,4,0)"
    .Range("S2").Formula = "=VLOOKUP(H2,'Mapping Table'!$B$21:$F$40,5,0)"
    .Range("T2").Formula = "=H2&"" ""&O2"
    .Range("U2").Formula = "=IF(M2=V2,""TRUE"",""FALSE"")"
    .Range("V2").Formula = "=IF(OR(M2=WORKDAY(TODAY(),-1),M2=WORKDAY(TODAY(),-2)),""Keep"",""Delete"")"
    .Range("W2").Formula = "=IF(M2=WORKDAY(TODAY(),-1),""Today"",""No"")"
    
    .Range("N2:W2").Copy .Range("N2:W" & r)
End With

End Sub

Open in new window

0
 
LVL 24

Expert Comment

by:broomee9
ID: 34971505
Is it in the same module, or is it in a class module?

What's the name of the module it's in?  Try this, assuming the module name is Module1

Module1.FillFormula

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:Seamus2626
ID: 34971603
its module5

i tried that and it didnt fill

Thanks
Seamus
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34971661
What does Datacall do? If it retrieves external data, my guess would be that that data refreshes in the background so your fillformula sub has nothing to fill when it runs (the data is still refreshing).
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34971668
Add this msgbox to the top of your module, and see if the message appears, then you'll know it's being called properly:


Sub FillFormula()

'Add this
msgbox "You made it in"

 'Your code here
 '.....
End Sub
0
 

Author Comment

by:Seamus2626
ID: 34971681
Your spot on Rorya, it is retrieving data.

So i need to run the fill data part later in the sub?
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 34971718
No, you just need to make sure that your data retrieval process does not use a background query. If you are using 2003 or earlier, right -click on the resulting data, choose Data Range Properties and uncheck the option to allow background refreshing. Or, if you are not using Refreshall but refreshing a specific table in code, you can specify the Backgroundquery:=false argument in the code.
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34971725
Why don't you just pause your code to let the datacall finish refreshing the data.


Add this to the very top of your module (right below Option Explicit)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Then do something like this:

Call Datacall
Sleep(10000) 'Wait 10 seconds
Call FillFormula
0
 

Author Closing Comment

by:Seamus2626
ID: 34971790
Thats the problem. Thanks Rorya.

Thank you too Broome9

Cheers,
Seamus
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question