extracting 3 columns into a new worksheet

gray123

New Member
Joined
Sep 11, 2016
Messages
24
Hi anyone,
looking for a bit more help in building my reservation manager, I have managed to add all my properties now & the code below is working fine.
I would now like to take columns C, E, & R including Header (which is on line 7 ) from the ("Reservations") sheet & have data & headers go to a new sheet called ("income") &
appear on Columns A & B, C but again allow me to have data in Columns D onwards that doesn't get cleared when I update the code.
I hope above makes sense, Thanks
Code:
 Sub copyData()
  Dim X As Long, IDs As Variant, Props As Variant, RR As Worksheet, IDcells As Range
  Set RR = Sheets("Reservations")
  IDs = Array("ID001", "ID002", "ID003", "ID004", "ID005", "ID006", "ID007", "ID008", "ID009", "ID010", "ID011", "ID012", "ID013", "ID014", "ID015", "ID017", "ID018", "ID019", "ID020", "ID021", "ID022", "ID023", "ID024", "ID025", "ID026", "ID027", "ID028", "ID029", "ID030", "ID031", "ID032", "ID033", "ID034", "ID035", "ID037", "ID039", "ID040", "ID042")
  Props = Array("ID1", "ID2", "ID3", "ID4", "ID5", "ID6", "ID7", "ID8", "ID9", "ID10", "ID11", "ID12", "ID13", "ID14", "ID15", "ID17", "ID18", "ID19", "ID20", "ID21", "ID22", "ID23", "ID24", "ID25", "ID26", "ID27", "ID28", "ID29", "ID30", "ID31", "ID32", "ID33", "ID34", "ID35", "ID37", "ID39", "ID40", "ID42")

  For X = LBound(IDs) To UBound(IDs)
    Sheets(Props(X)).Columns("A:F").Clear
    RR.Columns("D").Replace IDs(X), "#N/A", xlWhole
    Set IDcells = Intersect(RR.Columns("D").SpecialCells(xlConstants, xlErrors).EntireRow, RR.Range("A:A,B:B,C:C,G:G,R:R,S:S").EntireColumn)
    RR.Columns("D").Replace "#N/A", IDs(X), xlWhole
    IDcells.Copy Sheets(Props(X)).Range("A5")
    Intersect(RR.Rows(7), RR.Range("A1,B1,C1,G1,R1,S1").EntireColumn).Copy Sheets(Props(X)).Range("A4")
  Next
 End Sub
 [code]
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub MoveColumnsCandEandR()
  Dim LastRow As Long
  LastRow = Sheets("Reservations").Cells.Find("*", , xlFormulas, , xlRows, xlPrevious).Row
  Sheets("income").Range("A1:C" & LastRow - 6) = Application.Index(Sheets("Reservations").Cells, Evaluate("ROW(7:" & LastRow & ")"), Split("3 5 18"))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hi Rick,
I have a update Command button on the Reservation page, how do I get it to run both macros
 
Upvote 0

Forum statistics

Threads
1,216,070
Messages
6,128,613
Members
449,460
Latest member
jgharbawi

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