help!!

Young_Money

New Member
Joined
Jul 8, 2011
Messages
23
Hi guys. I am using UserForm to make what I want to do right now. What the program does is it has seven buttons. I separated them by three different categories. This is how it looks like
New Orders of Last Week
*"Carrier"button*
*"Enterprise"button*

Quotes and New Opportunities
*"Carrier"button*
*"Enterprise"button*

Top Opportunities
*"Carrier"button*
*"Enterprise"button*

and the last one is just information on how to use the userform.

What I'm doing right now is when I click the Carrier button under New Order, it copies what I highlighted into the New_Orders sheet starting at 1,1. I use the same code for all the Carrier buttons, but I just change the location that I want it to be to each respective sheet i.e "Quotes_and_New Oppportunities" and "Top_Opportunities" and "New_Orders". Below is the code I have for Carrier.

Sub CommandButton1_Click()

Dim rngCopy As Range
Dim rngPaste As Range

Set rngCopy = Selection
Set rngPaste = Sheets("New_Orders").Cells(1, 1)
rngCopy.Copy rngPaste

End Sub

I am getting the copy and paste list from a different sheet called "Sheet1"
Now comes the problem. I need to make it so that when I click the Enterprise button under New Orders, it counts the number of cells that have text in Column A in the sheet New_Orders, and then pastes the highlighted cells from "Sheet1" to "New_Orders" at the next empty cell, which would be right after the Carrier list that I pasted if I clicked Carrier, and then Enterprise after.

Can anybody help me out please?
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try

Code:
Sub CommandButton1_Click()

Dim rngCopy As Range
Dim rngPaste As Range

Set rngCopy = Selection
Set rngPaste = Sheets("New_Orders").Cells(Rows.Count, 1).End(xlUp).Offset(1)
rngCopy.Copy rngPaste

End Sub
 
Upvote 0
holy cow it works!
thanks alot!!

Just one question because I don't want to just take the code and not learn anything.

Can you please explain this line?

Set rngPaste = Sheets("New_Orders").Cells(Rows.Count, 1).End(xlUp).Offset(1)

How does Cells(Rows.Count, 1).End(xlUp).Offset(1) count the number of cells and know where to paste it? :O

Thanks again for all your help!
 
Upvote 0
Cells(Rows.Count, 1).End(xlUp) gets the last filled row. Offsetting by 1 gets the first empty cell.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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