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.
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