VBA Questions - Copying dynamic data from one tab to another and deleting filtered rows

NoneTheWiser

New Member
Joined
Mar 11, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I'm trying to create a macro which will move data from one tab to another, but the data isn't sequential. The original tab has 36 columns and the second tab only has 20, meaning there are 16 columns which don't require transferring. I only want to transfer the 20 columns if there is a value in the last column. I can copy the data across if it is static and is in the same rows constantly, but this can't be guaranteed. Can someone advise how this can be applied to dynamic data where the data in column C may not start in C2, and end in M3 (and the same for the remaining columns).

VBA Code:
ActiveSheet.Columns("A:AJ").AutoFilter Field:=36, Criteria1:="VALUE"

Range("C1").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Range("C2:M3").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste


Sheets("Sheet1").Select
Range("R2:R3").Select
Selection.Copy
Sheets("Sheet2").Select
Range("L1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste


Sheets("Sheet1").Select
Range("X2:AC3").Select
Selection.Copy
Sheets("Sheet2").Select
Range("M1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


Sheets("Sheet1").Select
Range("AH2:AI3").Select
Selection.Copy
Sheets("Sheet2").Select
Range("S1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

The next issue I have, is I want to delete the rows from sheet 1 after is has been copied to sheet 2 but the VBA code isn't working.

VBA Code:
Sheets("Pipeline").Select
ActiveSheet.Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select.Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete

Can anyone shed some light on this issue as to why it's not working? When the macro gets to the last section I receive an error message "Run-time error '424' object required" on the below line.

VBA Code:
Range(Selection, Selection.End(xlDown)).Select.Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete

Again appreciate any thoughts and comments on this.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi and welcome to MrExcel.

Delete "Select" word:
Rich (BB code):
Range(Selection, Selection.End(xlDown)).Select.Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete

Try:
VBA Code:
Range(Selection, Selection.End(xlDown)).Offset(1, 0).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

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