copy and paste to another sheet

Mattlake

Board Regular
Joined
Apr 9, 2020
Messages
91
Office Version
  1. 2021
Platform
  1. Windows
Hi

This may have already been asked so apologies if it has.

I have a spreadsheet which i need copy column A, B and column AV from 3 sheets and paste these into a new worksheet. I need to try and set this to happen automatically.

I think this will be a VBA before save (i think) is this actually possible?

if it isnt you can laugh :)

thank you

Matthew
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hello @Mattlake, thanks for posting on the forum.

You omitted some things:
- Like the name of the sheets to copy.
- The name of the new sheet.
- In which row does the data begin?
So fit "s5", "s6" and "s7" by the names of your sheets.
The macro creates a new sheet and names it "new sheet", but you can also adjust it.
The macro copies from row 1 to the last row with data from each sheet and pastes the data below the previous one.

I hope to cover all variants. 😅

VBA Code:
Sub copycolumns()
  Dim arr As Variant, itm As Variant
  Dim f As Range
  Dim sh As Worksheet, shNew As Worksheet
  Dim sName As String
  Dim lr As Long
  
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  
  sName = "New Sheet"               'Fit to the name of your new sheet
  
  On Error Resume Next: Sheets(sName).Delete: On Error GoTo 0
  Sheets.Add(, Sheets(Sheets.Count)).Name = sName
  Set shNew = Sheets(sName)
  
  lr = 1
  arr = Array("s5", "s6", "s7")     'Fit to the name of your sheets
  For Each itm In arr
    Set sh = Sheets(itm)
    Set f = sh.Range("A:AV").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
    If Not f Is Nothing Then
      sh.Range("A1:B" & f.Row & ",AV1:AV" & f.Row).Copy
      shNew.Range("A" & lr).PasteSpecial xlPasteValues
      Set f = shNew.Range("A:C").Find("*", , xlValues, xlPart, xlByRows, xlPrevious)
      If Not f Is Nothing Then
        lr = f.Row + 1
      End If
    End If
  Next
  
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0
Solution
Thank you for this. I think it will be easier to just tell the person to make a note of the columns before they adjust it
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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