VBA to Copy Data and Paste On a Loop

Jess709

New Member
Joined
Apr 24, 2015
Messages
20
I am in the early stages of learning VBA and Macros and am in need of assistance.

I have a spreadsheet with 2 tabs of data. First tab named "acctinfo" has 2 columns of data. Column A is for the account numbers and column B is for job descriptions. Second tab named "jobdescriptions" just has one column of data, A. At the present time there are 214 rows, but depending on the data there may be more rows than that.

I need to copy a set of data from the 2nd tab, named "JobDescriptions" and paste it into the 1st tab named "AcctInfo" In the JobDescriptions tab I want the macro to copy the data starting with the first cell under the column heading (i.e B2), until it reaches a blank cell. After the data is copied I want it to be pasted into the 1st tab starting in cell B2. I then want it to continue pasting that same set of data until the last cell that has a value column A (example A2:A214).

The objective is to provide our programming department with a spreadsheet of job descriptions for 49 accounts and each account has to have a row for every job description. For example, if there are 213 job descriptions then the spreadsheet will have 213 rows for account # 64104408, 213 rows for account # 6414409 and so on.

Here is a sample of what the final output would look like, shortened.

Thank you so much for any help you can provide!!
Acct #
Job Description
64104408
ACAD AFF STAFF ADM__UNCLASSIFIED
64104408
ACADEMIC AFFAIRS OF__UNCLASSIFIED
64104408
ACCOUNT CLERK__UNCLASSIFIED
64104408
ACCOUNTANT__UNCLASSIFIED
64104408
ACCOUNTANT 1__CLASSIFIED
64104408
ACCOUNTANT 2__CLASSIFIED
64104408
ACCOUNTANT 3__CLASSIFIED

<tbody>
</tbody>
 
I was able to get the code fixed, here it is in case anyone else wants to see:

Code:
Sub CopyJobDesc()
'
' CopyJobDesc Macro
 
 
    Sheets("JobDescriptions").Select
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("AcctInfo").Select
    Range("B2").Select
   
   
    Range("B" & Cells.Rows.Count).End(xlUp).Select
    Do Until IsEmpty(ActiveCell.Offset(1, -1))
    ActiveCell.Offset(1, 0).Select
    ActiveSheet.Paste
    Range("B" & Cells.Rows.Count).End(xlUp).Select
Loop
 
End Sub
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

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