Range as Active Cells Selection

powellku

New Member
Joined
Aug 13, 2020
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
Hey Excel Folks,

I'm having trouble with this one and I need some help.

My Objective: copy data from one excel sheet (rgSource) to a different destination sheet (rgDestination).

Problem: I can't get the Active cell selection to work and then have VBA automatically select the entire row.

Here's my code thus far:


Private Sub CommandButton4_Click()

'''' Move to Archive Button ''''

Dim rgSource As Range, rgDestination As Range
Set rgSource = ThisWorkbook.Worksheets("Database2").Range(Activecell.EntireRow) ''''Problem''''
Set rgDestination = ThisWorkbook.Worksheets("Archive").Range("A" & Application.Rows.Count).End(xlUp)

rgSource.Copy
rgDestination.PasteSpecial xlPasteValues

End Sub..

Thank you so much!

Sincerely,

kp
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If the button is on the DataBase2 sheet, then just use
VBA Code:
 Set rgSource = Activecell.EntireRow
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
If the button is on the DataBase2 sheet, then just use
VBA Code:
 Set rgSource = Activecell.EntireRow

One other question, now that section is working properly. I can't seem to get each row to add sequentially after another. I thought the code that I wrote "& Application.Rows.Count).End(xlUp)" would get VBA to add the next line of data sequentually, but its not doing that. Any suggestions?
 
Upvote 0
VBA Code:
Range("A" & Application.Rows.Count).End(xlUp)
selects the last row with data, not the first blank one after that.

You need to do this:
VBA Code:
Range("A" & Rows.Count).End(xlUp).Offset(1,0)
to select the first row after that.
 
Upvote 0
@Fluff and @Joe4, both of you are awesome! I've been struggling with this all week and now it's working. I can't thank you enough!!!
 
Upvote 0
You are welcome.
Glad we could help!
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,706
Members
449,118
Latest member
MichealRed

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