Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Excel VBA Copy data from two columns into new sheet

Hi

I have a spreadsheet with a number of sheets. There are two column in different positions.
Let's call them Column A and Column B.
How do I loop through all sheets using Excel VBA, locate these columns and copy them under each other
in a new sheet that lists all data in these columns
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Martin Liss
Avatar of Amir Azhdari
Amir Azhdari
Flag of United States of America image

Lets say Sheet3 is the new sheet that lists all data in those columns:
Please find attached:
Copy to Sheets.xlsm

Sub ReferToAnotherCell()
Dim RRow As Long, RDateCol As Long, N As Long, C As Long
C = 1
For N = 1 To ActiveWorkbook.Sheets.Count - 1
 For PRow = 1 To ActiveWorkbook.Sheets(N).UsedRange.Rows.Count
  ActiveWorkbook.Worksheets("Sheet3").Cells(C, 1).Value = ActiveWorkbook.Sheets(N).Cells(PRow, 1).Value
  ActiveWorkbook.Worksheets("Sheet3").Cells(C, 2).Value = ActiveWorkbook.Sheets(N).Cells(PRow, 2).Value
  C = C + 1
 Next PRow
 
Next N

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

I’m glad I was able to help and thank you for the testimonial.

If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Distinguished Expert in Excel 2018
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2020
              Experts Exchange Top Expert VBA 2018 to 2020
Avatar of Murray Brown
Murray Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks very much Martin
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

You're welcome.
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo