Copying entire Rows

NewbieMan

New Member
Joined
Nov 25, 2017
Messages
33
Hi,

My first post and thanks for the help in advance. Just learning VBA now and have a small question that I have been stuck on please.

Have the following...

Dim TeamID As Integer
Dim SearchRange As Range




AccessApp.DoCmd.OpenTable ("Coaches")
TeamID = InputBox(prompt:="Type the TeamID for your coach in the box below", Title:="Importing Coaches")


Set SearchRange = Columns("C:C")
SearchRange.Find(what:=TeamID).Select
ActiveCell.Offset(-1, 0).Select

Here is my problem...when I get to the TeamID cell and then up to the offset cell above it in column C, I then want to copy an array from cell A2 (fixed) down to and including the row containing the cell above TeamID cell and all the way over to the BC column (so that entire array) after accomplishing that I want to export into a specific table in access. What I am looking for is 1) how to copy that array , and then below it, 2) just a little nudge on how I would be able to paste that array into a specific table in access.

Thanks very much in advance. This is very much appreciated.

Cheers,
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I'm not familiar with using Access so this macro is missing that part but it will copy the rows that you requested. You would have to add the pasting to Access part of it. I hope this helps.
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim foundRow As Long
    Dim TeamID As Long
    TeamID = InputBox(prompt:="Type the TeamID for your coach in the box below", Title:="Importing Coaches")
    foundRow = Columns("C:C").Find(what:=TeamID).Row
    ActiveSheet.Rows("2:" & foundRow - 1).EntireRow.Copy
    'code to paste in Access
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
I'm not familiar with using Access so this macro is missing that part but it will copy the rows that you requested. You would have to add the pasting to Access part of it. I hope this helps.
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim foundRow As Long
    Dim TeamID As Long
    TeamID = InputBox(prompt:="Type the TeamID for your coach in the box below", Title:="Importing Coaches")
    foundRow = Columns("C:C").Find(what:=TeamID).Row
    ActiveSheet.Rows("2:" & foundRow - 1).EntireRow.Copy
    'code to paste in Access
    Application.ScreenUpdating = False
End Sub

Thanks mumps. One small issue otherwise it works fine. Just wondering how I can make an adjustment so that the entire row is copied only as far as Column "BC". As of right now it copies all columns.

Thanks.
 
Upvote 0
Replace:
Code:
ActiveSheet.Rows("2:" & foundRow - 1).EntireRow.Copy
with
Code:
ActiveSheet.Range("A2:BC" & foundRow - 1).Copy
 
Upvote 0

Forum statistics

Threads
1,223,957
Messages
6,175,625
Members
452,661
Latest member
Nonhle

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