Cannot select/copy upper range in Excel

Dad_x6

Board Regular
Joined
Jan 15, 2013
Messages
89
I have a very large spreadsheet (850 columns and 5000 rows) that I am trying parse into smaller chunks and then send into Access.

I have a loop that cycles through the columns and sends 120 columns at a time to a separate workbook (via a strRange) variable. Then, the new workbook is imported by Access into it's own table (yes I know... That is W-A-Y too many columns for an Access table).

Anyway, the process works great through the 4th set, and then I start getting Run-time error 1004 when it tries to either copy or select the range QH1:VJ4791, or any range higher than that.

I have tried the following...

a) ActiveSheet.Range(strRange).Copy Destination:=wbHolder.Sheets(1).Range("B1")
b) ActiveSheet.Range(strRange).Copy
c) ActiveSheet.Range(strRange).Select

Same error everytime, unless the range is smaller letters. So for example the 4th round's range is MX1:QG4791, and that one works without difficulty.

Here is the code I am using for the copy range part (the importing to Access is handled by Access). I also included the Excel Column Letter function so you could see what I am doing.

Code:
Option Explicit

Public Sub AccessImport(intTable As Integer, c As Long)
    Dim wbHolder As Object
    Dim lngRC As Long
    Dim strRange As String

    lngRC = Sheets("Master").UsedRange.Rows.Count
    Set wbHolder = Workbooks("AT_Holder.xlsx")
    ThisWorkbook.Activate
    strRange = ConvertToLetter(c) & "1:" & ConvertToLetter(c + 119) & CStr(lngRC)
    ActiveSheet.Range(strRange).Copy Destination:=wbHolder.Sheets(1).Range("B1")
    wbHolder.Application.DisplayAlerts = False
    wbHolder.Save
    wbHolder.Application.DisplayAlerts = True
    Set wbHolder = Nothing
    
End Sub


Function ConvertToLetter(iCol As Long) As String
   Dim iAlpha As Integer
   Dim iRemainder As Integer
   iAlpha = Int(iCol / 27)
   iRemainder = iCol - (iAlpha * 26)
   If iAlpha > 0 Then
      ConvertToLetter = Chr(iAlpha + 64)
   End If
   If iRemainder > 0 Then
      ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
   End If
End Function
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Here is some new information. I attempted building strRange in a different way (strRange = "QH" & "1:" & "VJ" & "4791") just to see if it would work. And it DID! So something appears to be causing it with the ConvertToLetter calls I make. But why would that be an issue on the 5th round, when it is not on rounds 1 through 4?
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top