Hello All,
Long time reader, first time poster. Thanks to the entire community for helping me learn every day.
I have a workbook that queries an access database and then copy / paste / transposes each row to a column on a region specific tab to re-create a sheet that is used by the entire sales team. Unfortunately, when testing the code below, it took almost an hour to move <400 test records. Before I added the Save after each row, it would bomb out 50 records in because it ran out of memory. Any assistance on how to clean up my cobbled together solution to this problem is most appreciated. If I am going about this the wrong way, I am open to changing approaches. I just need the rows of data from the db to end up in columns on the spreadsheet. Where, when, and how that happens is flexible. I am a contractor hoping to get hired full-time and this working smoothly will go a long way toward impressing the management.
Thanks again for any help anyone can provide for me.
Long time reader, first time poster. Thanks to the entire community for helping me learn every day.
I have a workbook that queries an access database and then copy / paste / transposes each row to a column on a region specific tab to re-create a sheet that is used by the entire sales team. Unfortunately, when testing the code below, it took almost an hour to move <400 test records. Before I added the Save after each row, it would bomb out 50 records in because it ran out of memory. Any assistance on how to clean up my cobbled together solution to this problem is most appreciated. If I am going about this the wrong way, I am open to changing approaches. I just need the rows of data from the db to end up in columns on the spreadsheet. Where, when, and how that happens is flexible. I am a contractor hoping to get hired full-time and this working smoothly will go a long way toward impressing the management.
VBA Code:
Sub CopyRows()
Dim rngMyRange As Range, rngCell As Range
Dim sht As Worksheet
Dim LastColumn As Long
Dim SheetName As String
Dim SaveColNdx
Application.ScreenUpdating = True
With Worksheets("Bid Sheet Query")
Set rngMyRange = .Range(.Range("a2"), .Range("A65536").End(xlUp))
For Each rngCell In rngMyRange
rngCell.EntireRow.Select
Selection.Copy
SheetName = rngCell.Value
Sheets(SheetName).Select
Set sht = ThisWorkbook.Worksheets(SheetName)
Range("A1:PP1").Select
Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, Lookat:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Activate
SaveColNdx = ActiveCell.Column
Columns(SaveColNdx).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Sheets("Bid Sheet Query").Select
ActiveWorkbook.Save
Next
End With
End Sub
Thanks again for any help anyone can provide for me.
Last edited by a moderator: