Results 1 to 2 of 2

Error "#BUSY!"

Threaded View

VAer Error "#BUSY!" 09-01-2021, 08:42 AM
bakerman2 Re: Error "#BUSY!" 09-01-2021, 08:46 AM
  1. #1
    Forum Contributor VAer's Avatar
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    801

    Error "#BUSY!"

    Could someone please help me fix the code (attached)? What is wrong with it?

    It used to work fine, when I get historical data into Sheet "Dashboard" (right hand side of Dashboard), per my earlier thread https://www.excelforum.com/excel-pro...-function.html

    Now I am trying to clean up code and put historical data in a different sheet (adding sheet "Historical Data"), it turns out error "#BUSY!" There is only sheet change from previous code, but it does not get historical data now. I don't know where I mess up.

    How to fix it? Function Last works correctly.

    Thanks.

    Edit: Thanks. I was trying to share file on google drive, now it shows up correctly (no issue now). Not sure why, after closing the file and reopening the file, the historical data pops up.

    Sub GetHistoricalData()
    
    Dim LastRowC As Integer
    Dim Rng As Range
    Dim LastCol As Integer
    Dim i As Integer
    Dim ShtDashboard As Worksheet
    Dim ShtHistoricalData As Worksheet
    
    
    Set ShtDashboard = ThisWorkbook.Sheets("Dashboard")
    Set ShtHistoricalData = ThisWorkbook.Sheets("Historical Data")
    
    
    
    ShtHistoricalData.Columns(1).Resize(, 16000 - (1 - 1)).ColumnWidth = 15
    
    
    
    Range(ShtHistoricalData.Cells(1, 1), ShtHistoricalData.Cells(1000, 16000)).ClearContents
    
    Set Rng = Range(ShtHistoricalData.Cells(1, 1), ShtHistoricalData.Cells(1000, 16000)) '1000 is random row number, it is enough for 30 days of data, I may pull more data, but unlikely more than 1000 days; 16000 is random column number, there are 16384 columns on a worksheet. 
    
    LastRowC = ShtDashboard.Cells(Rows.Count, "C").End(xlUp).Row 'I have a list of symbol in column C, less than 2000 companies, above random number 16000 is enough
    
    For i = 2 To LastRowC
    
        LastCol = Last(2, Rng)
        
        If LastCol < 1 Then
            ShtHistoricalData.Cells(1, 1).Value = ShtDashboard.Cells(i, 3).Value
            ShtHistoricalData.Cells(2, 1).Formula2 = "=STOCKHISTORY(" & """" & ShtHistoricalData.Cells(1, 1).Value & """" & ",TODAY()-30,TODAY())"
            
            
        Else
            ShtHistoricalData.Cells(1, LastCol + 3).Value = ShtDashboard.Cells(i, 3).Value
            ShtHistoricalData.Cells(2, LastCol + 3).Formula2 = "=STOCKHISTORY(" & """" & ShtHistoricalData.Cells(1, LastCol + 3).Value & """" & ",TODAY()-30,TODAY())"
        
        End If
        
        
    Next i
    
    
    
    MsgBox "Done"
    
    
    
    End Sub
    
    
    
    
    Function Last(choice As Long, Rng As Range)
    ' 1 = last row
    ' 2 = last column
    ' 3 = last cell
        Dim lrw As Long
        Dim lcol As Long
    
        Select Case choice
    
        Case 1:
            On Error Resume Next
            Last = Rng.Find(What:="*", _
                            after:=Rng.Cells(1), _
                            LookAt:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
            On Error GoTo 0
    
        Case 2:
            On Error Resume Next
            Last = Rng.Find(What:="*", _
                            after:=Rng.Cells(1), _
                            LookAt:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Column
            On Error GoTo 0
    
        Case 3:
            On Error Resume Next
            lrw = Rng.Find(What:="*", _
                           after:=Rng.Cells(1), _
                           LookAt:=xlPart, _
                           LookIn:=xlFormulas, _
                           SearchOrder:=xlByRows, _
                           SearchDirection:=xlPrevious, _
                           MatchCase:=False).Row
            On Error GoTo 0
    
            On Error Resume Next
            lcol = Rng.Find(What:="*", _
                            after:=Rng.Cells(1), _
                            LookAt:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Column
            On Error GoTo 0
    
            On Error Resume Next
            Last = Rng.Parent.Cells(lrw, lcol).Address(False, False)
            If Err.Number > 0 Then
                Last = Rng.Cells(1).Address(False, False)
                Err.Clear
            End If
            On Error GoTo 0
    
        End Select
    End Function
    Attached Images Attached Images
    Last edited by VAer; 09-01-2021 at 08:56 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 02-24-2019, 10:07 AM
  2. Replies: 35
    Last Post: 01-13-2016, 02:16 AM
  3. = EMBED("Forms.ComboBox.1","") error "Reference not valid."
    By CatharinaCatharina in forum Excel General
    Replies: 2
    Last Post: 12-11-2014, 09:58 AM
  4. [SOLVED] If Not ActiveSheet.Range("A1").Value Like "apple" Then MsgBox "Error"
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-18-2014, 02:16 PM
  5. [SOLVED] What are "ie.readyState" and "ie.Busy" for ?
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2013, 04:24 AM
  6. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  7. What is Error "Method "Paste" of object "_Worksheet" failed?
    By vat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-17-2006, 04:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1