Repeat 1 cell as many times as there are entries in another column

mt03530

New Member
Joined
Feb 1, 2018
Messages
18
Hello!

My ultimate goal is to pull 3 types of information from n number of worksheets into a summary page. I was successful with copying and pasting unique values (see below), however, I am having issues copying one cell from each worksheet and having it repeat multiple times.

I have multiple worksheets that look something like this:
[TABLE="width: 200"]
<tbody>[TR]
[TD]Amanda[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ID[/TD]
[TD]Color[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Gold[/TD]
[/TR]
</tbody>[/TABLE]

My code for copying ID and Color is:
Code:
Private Sub CommandButton1_Click()
    Dim wks As Worksheet


     
    For Each wks In ThisWorkbook.Worksheets
        If Not wks.Name = "Summary" Then
            wks.Range("A7:A" & wks.Cells(Rows.Count, "A").End(xlUp).Row).Copy _
            Destination:=Worksheets("Summary").Cells(Rows.Count, "A").End(xlUp).Offset(1)
               wks.Range("D7:D" & wks.Cells(Rows.Count, "D").End(xlUp).Row).Copy _
            Destination:=Worksheets("Summary").Cells(Rows.Count, "B").End(xlUp).Offset(1)


        End If
    Next
    
    
End Sub


Without having to count the number of entries myself, how do I now copy "Amanda" for each entry for Amanda (in this case 3 times)? Thanks!
 
How about
Code:
Private Sub CommandButton1_Click()
   Dim Wks As Worksheet
   Dim Rng As Range
   
   With Sheets("Summary")
      For Each Wks In ThisWorkbook.Worksheets
         If Not Wks.Name = "Summary" Then
            Set Rng = Wks.Range("A7:A" & Wks.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
            With .Range("A" & .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
               Rng.Copy .Offset(1)
               Rng.Offset(, 3).Copy .Offset(1, 1)
               .Offset(1, 2).Resize(Rng.Count).Value = Wks.Range("A4")
               Set Rng = Nothing
            End With
         End If
      Next Wks
   End With
   
End Sub
This assumes that you have something in the summary sheet when you run the code

This is perfect!!!
Thank you so much for all your help!! I really appreciate it!

As a beginner, may I ask how you learned VBA so well?
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Glad to help & thanks for the feedback

Most of what I know has been gleaned from this site over a number of years.
 
Upvote 0
Hello Fluff, could you elaborate further on the learning process. Did you take procedures from this site and analyze them by looking up VBA help, did you have a prior background in programming etc. I am learning myself but the process is hard and simple procedures seem to take literally 3hrs that someone with your skills would have it done in 30 minutes and probably less. I have reviewed a lot of your code and its amazing in its usefulness so while I can't speak for everyone, thank you for your efforts.
 
Upvote 0
Initially (when I was a lurker) I was simply trying to find some code that was similar to what I needed & would then try to understand it enough so that I could modify it to suit.
Then, when I became unemployed, I had plenty of time on my hands & started getting very active on here trying to help others.
When there wasn't much I could help with, I'd find a post that I didn't know how to answer (but which had already been answered) & would do some research to find out how to do it.
Once I had managed to get a macro that worked I'd compare it to the answer already supplied & if different to mine try & figure out the other macro.

At the same time some MVPs would post code to threads I was involved in pointing out other options & ways of doing things, which helped me learn even more.
 
Upvote 0
mbpress01,

See if something, in the below link(s), of my most up to date list will help you:

Training / Books / Sites as of 2/3/2018

What Is VBA?
https://www.techwalla.com/articles/what-is-vba

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
http://www.mrexcel.com/forum/mrexcels-products-books-cds-podcasts/
http://www.mrexcel.com/store/index.php?l=product_detail&p=306

There are over 1800 Excel videos/tutorials here:
http://www.youtube.com/user/ExcelIsFun

Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

MrExcel's Excel Tutorial Listing
http://www.mrexcel.com/articles.shtml

[VBA] Difference between OLEFormat and ControlFormat?
For references purposes and excellent explanations, see
http://wellsr.com/vba/excel/#guides

Excel VBA MACRO Kick-start Course for absolute beginner

Free VBA Course
http://www.excel-pratique.com/en/vba.php

Excel 2007 VBA materials to learn here:
http://www.worldbestlearningcenter.com/index_files/excel-VBA-understanding.htm

The macro recorder actually is your friend but look here:
http://www.tushar-mehta.com/excel/vba/beyond_the_macro_recorder/

Introduction to Variables, Constants and Data Types
http://msdn.microsoft.com/en-us/library/aa242127(v=vs.60).aspx

Declaring Variables
http://www.cpearson.com/excel/declaringvariables.aspx

Here's a good primer on the scope of variables.
http://www.cpearson.com/excel/scope.aspx
Variable Scope in Excel VBA - EASY Excel Macros
Understanding Scope

Using Variables in Excel VBA Macro Code
http://www.ozgrid.com/VBA/variables.htm

See David McRitchie's site if you just started with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

What is a VBA Module and How is a VBA Module Used?
http://www.emagenit.com/VBA Folder/what_is_a_vba_module.htm

Events And Event Procedures In VBA
http://www.cpearson.com/excel/Events.aspx

Here is a good introductory tutorial using a VBA Class:
http://www.cpearson.com/excel/classes.aspx

There's a chapter on classes in VBA Developer's Handbook which is also good.
http://www.amazon.com/VBA-Developers-Handbook-2nd-Edition/dp/0782129781

Ron's Excel Tips
http://www.rondebruin.nl/tips.htm

Ron de Bruin's Mail from Excel and make/mail PDF files (Windows)
http://www.rondebruin.nl/win/section1.htm

How do I create and use a PERSONAL file for my VBA code
http://www.rondebruin.nl/win/personal.htm

Anthony's Excel VBA Page - Excel Application - Excel Consultant - Excel Consulting (see 3 tutorials in Excel VBA Basic Tutorial Series)

BET: Microsoft Excel Visual Basic

Debugging VBA
http://www.cpearson.com/Excel/DebuggingVBA.aspx

Debug Excel VBA Macro Code
http://www.ozgrid.com/VBA/debug.htm

TechBookReport - Debugging Excel VBA Code
http://www.techbookreport.com/tutorials/debug_excel_vba_01.html

Here are some general links on performance improvement:
https://www.soa.org/News-and-Publica...s42-roper.aspx
Optimize Slow VBA Code. Speed Up Efficient VBA Code/Macros
Excel VBA Performance Coding Best Practices - Office Blogs
https://msdn.microsoft.com/en-us/library/aa730921.aspx

Start at the beginning...

Creating An XLA Add-In For Excel, Writing User Defined Functions In VBA
http://www.cpearson.com/excel/createaddin.aspx

Build an Excel Add-In
http://www.fontstuff.com/vba/vbatut03.htm

Creating custom functions
http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Your_First_VBA_Function_in_Excel/631.html

VBA for Excel (Macros)
http://www.excel-vba.com/excel-vba-contents.htm

Excel Macros Tutorial
http://www.excel-vba.com/excel-vba-contents.htm

Excel Macros & Programming
http://www.excel-vba.com/index.htm

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Beyond Excel's recorder

Helpful as a simple concise reference for the basics, and, using the macro recorder is endlessly powerful.
http://www.techonthenet.com/excel/cells/index.php

Learn to debug:
http://www.cpearson.com/excel/debug.htm

How To: Assign a Macro to a Button or Shape
http://peltiertech.com/WordPress/how-to-assign-a-macro-to-a-button-or-shape/

User Form Creation
http://www.contextures.com/xlUserForm01.html

Build a UserForm for Excel
http://www.fontstuff.com/ebooks/free/fsuserforms.pdf

When To Use a UserForm & What to Use a UserForm For
http://www.ozgrid.com/Excel/free-training/ExcelVBA2/excelvba2lesson2.htm

UserForms in Excel VBA - UserForm Basics; Add Controls dynamically at run-time using the Add Method; UserForm Controls (A Snapshot)

VBA add UserForm on the fly
http://www.vbaexpress.com/kb/getarticle.php?kb_id=228

Excel VBA how to Personalise the Ribbon
http://www.bing.com/videos/search?q...l+vba+how+to+Personalise+the+Ribbon&FORM=VDRE

Excel Tutorials / Video Tutorials - Functions
http://www.contextures.com/xlFunctions02.html

How to insert Buttons, radio buttons and check boxes in Excel
http://www.bing.com/videos/search?q...io+buttons+and+check+boxes+in+Excel&FORM=VDRE

INDEX MATCH - Excel Index Function and Excel Match Function
http://www.contextures.com/xlFunctions03.html

Multi or two way vlook up and index match tutorial
http://www.get-digital-help.com/

Excel Data Validation
http://www.contextures.com/xlDataVal08.html#Larger
http://www.contextures.com/excel-data-validation-add.html

Excel -- Data Validation -- Create Dependent Lists
http://www.contextures.com/xlDataVal02.html

http://www.get-digital-help.com/201...s-containing-unique-distinct-values-in-excel/

Your Quick Reference to Microsoft Excel Solutions
http://www.xl-central.com/index.html

New! Excel Recorded Webinars
http://www.datapigtechnologies.com/ExcelMain.htm

MS Excel: VBA Functions - Listed by Category
MS Excel: ALL Formulas/Functions - Listed by Category

Fuzzy Matching - new version plus explanation
http://www.mrexcel.com/forum/excel-questions/195635-fuzzy-matching-new-version-plus-explanation.html

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
http://www.cpearson.com/Excel/vbe.aspx

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

John Walkenbach's power programming with Excel books.

Excel 2010 Power Programming with VBA, Mr. Spreadsheet's Bookshelf

by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
Professional Excel Development

by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
Excel 2002 VBA: Programmers Reference

Professional Excel Development by Rob Bovey, Dennis Wallentin, Stephen Bullen, & John Green

DonkeyOte: My Recommended Reading, Volatility
http://www.decisionmodels.com/calcsecretsi.htm

A list of Reference Books
http://www.andypope.info/books/books.htm

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Need to understand error handling
http://www.cpearson.com/excel/errorhandling.htm

Excel file error message
How to diagnose Excel file corruption and repair workbooks

If a file cannot be repaired, consider recovering an earlier version from your file history
https://support.microsoft.com/en-us/...8-file-history

Arrays
http://www.mrexcel.com/forum/excel-questions/390246-vba-array-basics.html
http://www.cpearson.com/excel/VBAArrays.htm
http://www.xtremevbtalk.com/showthread.php?t=296012
http://www.vbtutor.net/vba/vba_chp21.htm
http://excelmacromastery.com/Blog/index.php/the-complete-guide-to-using-arrays-in-excel-vba/

Array Dimensions in Visual Basic - Working with Dimensions (code and graphics)
http://msdn.microsoft.com/en-us/library/02e7z943(v=VS.80).aspx

Visual Basic Array Tutorial written by Adam Wehmann
http://patorjk.com/programming/tutorials/vbarrays.htm

Shortcut Keys in Excel 2000 through 2007

Pivot Intro
http://peltiertech.com/Excel/Pivots/pivotstart.htm
Office 2010 Class #36: Excel PivotTables Pivot Tables 15 examples (Data Analysis) - YouTube
http://www.youtube.com/watch?v=qMGILHiLqr0
Getting Started with Pivot Tables
http://www.contextures.com/xlPivot01.html#Start
Overview of PivotTable and PivotChart reports
http://office.microsoft.com/en-gb/e...table-and-pivotchart-reports-HP010342752.aspx
Build a Pivot Table in Excel VBA
http://www.brainbell.com/tutorials/Excel_VBA/Build_A_Pivot_Table_In_Excel_VBA.html

Excel 2013 PowerPivot Basics #01: Introduction To PowerPivot for Excel 2013 - YouTube

Conditional Formatting
http://office.microsoft.com/en-001/...apply-conditional-formatting-HA102809768.aspx

Count cells based on Conditional Formatting color?
http://www.cpearson.com/Excel/CFColors.htm
http://www.excelfox.com/forum/showt...-(whether-from-Conditional-Formatting-or-not)
https://stackoverflow.com/questions...-of-a-conditionally-formatted-cell-in-excel-2

Email from XL - VBA
http://www.rondebruin.nl/sendmail.htm

Outlook VBA
https://www.rondebruin.nl/win/section1.htm
http://www.outlookcode.com/article.aspx?id=40
Exporting Email Body Text to excel (using outlook 2010) VBA
Exporting text from body of outlook email to excel
Quickly export Outlook e-mail items to Excel - TechRepublic

Mail a message to each person in a range
http://www.rondebruin.nl/win/s1/outlook/bmail5.htm

Excel VBA Dictionary – A Complete Guide
https://excelmacromastery.com/vba-dictionary/

Excel Function Dictionary by Peter Noneley
http://www.xlfdic.com/
http://www.hoffits.com/

Function Translations
http://www.piuha.fi/excel-function-name-translation/

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

Vba to create waterfall charts
http://peltiertech.com/excel-waterfall-charts-bridge-charts/

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
http://chandoo.org/wp/excel-dashboards/
http://chandoo.org/wp/management-dashboards-excel/
http://www.exceldashboardwidgets.com/
http://www.andypope.info/charts/gauge.htm
https://exceldashboardschool.com/
https://www.youtube.com/user/OnLinePCLearning/featured

To create my Dashboard I use this small ebook: Create a Dashboard using PivotTable - Roger F. Silva
https://www.amazon.com/Create-Dashb...?s=digital-text&ie=UTF8&qid=1486600546&sr=1-3

Excel Dashboard / Scorecard Ebook
http://www.qimacros.com/excel-dashboard-scorecard.html

Free dashboard training materials
https://www.google.com.hk/search?q=...rome..69i57.2835j0j8&sourceid=chrome&ie=UTF-8
https://www.youtube.com/user/OnLinePCLearning/featured

Excel Dashboard School
https://exceldashboardschool.com/

Mike Alexander from Data Pig Technologies
http://www.amazon.com/Excel-2007-Da...=sr_1_1?s=books&ie=UTF8&qid=1305564958&sr=1-1

Templates
http://www.cpearson.com/Excel/Topic.aspx
http://www.contextures.com/excel-template-golf-scores.html
http://www.ozgrid.com/search/templates.htm
http://www.onlinepclearning.com/
https://www.youtube.com/user/OnLinePCLearning/featured

Financial Model Template
https://www.youtube.com/results?sear...finance&page=1

Microsoft Excel Cascading Listboxes Tutorial
http://www.youtube.com/watch?v=YAMvLJRwZdI

Date & Time stamping:
http://www.mcgimpsey.com/excel/timestamp.html

Get Formula / Formats thru custom functions:
http://dmcritchie.mvps.org/excel/formula.htm#GetFormat

A nice informative MS article "Improving Performance in Excel 2007"
http://msdn.microsoft.com/en-us/library/aa730921.aspx

Progress Meters
http://www.andypope.info/vba/pmeter.htm
http://www.xcelfiles.com/ProgressBar.html

How to convert text to numbers in Excel
http://support.microsoft.com/kb/291047

How to parse data from the web - Brett Fret has a video in YouTube
http://www.youtube.com/watch?v=6H7tBL97orE

Excel VBA MAC shortcuts
http://www.mrexcel.com/forum/excel-questions/465614-mac-shortcuts-excel.html

http://www.internet4classrooms.com/excel_keyboard_mac.htm
http://office.microsoft.com/en-us/mac-excel-help/excel-keyboard-shortcuts-HA102927337.aspx

http://office.microsoft.com/en-us/excel-help/excel-shortcut-and-function-keys-HP010073848.aspx

Excel VLOOKUP Multiple Sheets • My Online Training Hub

Wise Owl Tutorials
https://www.youtube.com/playlist?list=PLNIs-AWhQzckr8Dgmgb3akx_gFMnpxTN5
https://www.youtube.com/watch?v=KHO5NIcZAc4&feature=youtu.be&list=PLNIs-AWhQzckr8Dgmgb3akx_gFMnpxTN5

http://msdn.microsoft.com/en-us/library/cc837974.aspx
Merging Data from Multiple Workbooks into a Summary Workbook in Excel
Merge data from all workbooks in a folder
Merging a Range from Selected Workbooks
Merging a Range from Multiple Workbooks by Column
Merging a Range from Multiple Workbooks in a Folder with a Filter

Filtering Horizontally, or both
https://www.mrexcel.com/forum/excel-questions/922023-filtering-horizontally.html
https://www.mrexcel.com/forum/excel-questions/746452-horizontal-filtering-macros.html
http://blog.livedoor.jp/andrewe/archives/50283818.html
https://stackoverflow.com/questions/16822916/best-way-to-filter-both-vertically-and-horizontally
https://chandoo.org/forum/threads/filter-horizontally-instead-of-vertically.14283/

You could do a Google search with “You Tube” and use the foollowing names, and/or, links:
https://www.youtube.com/watch?v=ABXP...S5k4zsvnu2mkJC
https://www.youtube.com/watch?v=KHO5...3akx_gFMnpxTN5
https://www.youtube.com/watch?v=kd6Z...VH5Dq42RG9tlRP
https://www.youtube.com/watch?v=AIhK...suD6oNDaOk3vbR
https://www.youtube.com/watch?v=Z08z...Z_6brD5Gk1sVy_
https://www.youtube.com/user/ExcelVbaIsFun/playlists
https://www.youtube.com/watch?v=o_d8...lhXL_9m7EAgcMq
https://www.youtube.com/user/ExcelVB...ort=dd&view=50
https://www.youtube.com/playlist?lis...o2SEPBLLPGOyBz
https://www.youtube.com/watch?v=y_1e...7lleNVtNeAhBVC
https://www.youtube.com/watch?v=CDYk...007E847B3E6658

Some other Threads where VBA learning was discussed:
Basics of Excel VBA and Code writting
Excel VBA
http://www.excelforum.com/excel-for...-my-macro-is-launched-from-2.html#post4250487
http://www.excelforum.com/excel-general/1111289-how-useful-are-youtube-tutorials-for-vba.html
https://members.excelcampus.com/a/1523/fdzAdugs

Sending mail from Excel with CDO
http://www.rondebruin.nl/win/s1/cdo.htm

And, as your skills increase, try answering threads on sites like:
http://www.mrexcel.com
http://www.excelforum.com
http://www.ozgrid.com
http://www.vbaexpress.com
http://www.excelfox.com

If you are willing to spend money for the training, then something here should work for you...
http://www.amazon.com/s/?ie=UTF8&ke...vpone=&hvptwo=&hvqmt=b&ref=pd_sl_5givffg47i_b

Advanced Excel Training - Online Excel Course
http://www.udemy.com/advanced-excel/

Learn VBA Fast, Vol. I: Excel function design course, with practice exercises (The VBA Function Design Course Book 1)
http://www.amazon.co.uk/dp/B00M6E8MBW

Excel VBA Programmer Interview - Excel Test for interview
http://www.vbaexpress.com/forum/showthread.php?48406-Excel-VBA-Programmer-Interview&

Excel tests
http://www.excel-skills.com/demos2010/skills_test.php
http://www.skills-assessment.net/home/frmIndex.aspx?e=135
https://www.wiziq.com/tests/ms-excel

Here is another Function translator that is extremely popular:
http://en.excel-translator.de/functions/text/
It will also translate Formulas as well
http://en.excel-translator.de/translator/

Here a couple of good blogs on the R1C1 Style Notation
https://smurfonspreadsheets.wordpress.com/2007/11/12/r1c1-notation/
http://powerspreadsheets.com/r1c1-formular1c1-vba/

Top ten ways to clean your data
https://support.office.com/en-us/ar...our-data-a64879eb-115f-4e3d-a3bf-9cfc08a0a4e3

Analytical reasoning test of Excel aptitude
http://www.exceltip.com/wp-content/uploads/2015/07/Download-Top-30-Microsoft-Interview-Questions.pdf

RegEX question - Alpha only upper case only.
Regex Tutorial—From Regex 101 to Advanced Regex
Regular Expression Tutorial - Learn How to Use Regular Expressions
https://www.princeton.edu/~mlovett/r...xpressions.pdf

The VBA Guide To ListObject Excel Tables
https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables

Hiding Macros
https://www.mrexcel.com/forum/excel-questions/1030101-hiding-macros.html

Excel keyboard shortcuts
http://www.asap-utilities.com/excel-tips-shortcuts.php
A nearly complete Microsoft list, from thisoldman:
https://support.office.com/en-us/art...9-9b7213f0040f
This has some that aren't listed on the MS page:
http://www.asap-utilities.com/excel-tips-shortcuts.php
And this one:
https://exceljet.net/keyboard-shortcuts
Microsoft changed some shortcuts between 2003 and 2007 versions and they continue to change them.
Menu shortcuts, get changed too.
If you have a newer version of Excel, type Alt+d and a message will pop up: "Continue typing the menu key sequence ..."
My favorite little known key sequences are the context menu shortcuts.
If you're on Windows with a keyboard that has a menu key, copy a range of cells, then select a destination.
Press the menu key (between Rt-Alt and Rt-Ctrl) then press V to paste values only, or R to paste formats only, or T to transpose+paste.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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