+ Reply to Thread
Results 1 to 8 of 8

If sheet name equals range

  1. #1
    Registered User
    Join Date
    05-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    4

    If sheet name equals range

    Hi All,

    I need help creating a macro and have not been able to find the solution I'm looking for in this thread so figured I would make my first post. I need help creating a macro that copies a cell from one sheet into another sheet based on the name of that sheet.

    I have included dummy data for an example below. In this example, my workbook has 3 blank sheets named Example 1, Example 2, Example 3, and fourth sheet called Template, which includes the data below. I would like the macro to take the numbers in the input column and put them into their corresponding sheet in cell A1 of that sheet. For example, sheet "Example 1" will include "10" in cell A1 and sheet "Example 2" will include "20" in cell A1.

    Sheet Name Input
    Example 1 10
    Example 2 20
    Example 3 30

    I recognize this is very simplistic, but I will be repeating this processes for over 20 inputs and the inputs / sheet names will update every quarter/year. The data will always be in the same spot in the "Template" tab and the data will always be input into the same cells in the various sheets, but the number of sheets and inputs themselves will change each time this is ran.

    Appreciate any help with this!

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,526

    Re: If sheet name equals range

    For starters.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: If sheet name equals range

    Hi rook and welcome to the forum,

    See if this code will start you in the correct direction...
    Please Login or Register  to view this content.
    WithWorksheetPutValue.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    05-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    4

    Re: If sheet name equals range

    Hi Marvin,

    Really appreciate the help with this! It was able to work and I have been able to replicate for other instances that I need.

    One follow up question for you. Is there a simple tweak I could make to the code you previously provided that would perform this function for a few cells at a time? So Assume I now have columns Input 1 - Input 3 and I want to put them in each sheet based on the sheets name in columns A - C (i.e. A1, B1, C1 cells would all have a value now). I tried updating the ["Range("A1") = Cells(RowCtr, "B")] section of the code but was not getting it to work.

    Thanks in advance!

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: If sheet name equals range

    Hey Rook,

    It would a lot better if you could show what you tried and even give us a sample workbook. Did you have exactly 3 input columns? Did you want the number of columns to be variable? My best guess with your updating code is you didn't put the period before the word "Range". Show me what you tried and give me a sample workbook with the harder problem and I'll see what I can do.

  6. #6
    Registered User
    Join Date
    05-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    4

    Re: If sheet name equals range

    Hi Marvin,

    I attached an example workbook with the desired output. It will always be the same number of columns that will be required to be copied into each sheet and they will be copied in the same location on each sheet (i.e. cells B2:H2 from the template sheet will be copied to cells B10:H10 in each sheet). The only variable in my example is the number of tabs, which is based on the number of sheet names in column A from the template tab.
    Attached Files Attached Files

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: If sheet name equals range

    OK Rook,

    The With and Period before the Cells is of huge importance. When you use the Dot or Period in front of a Range or Cells it means to go to the "With" sheet. See if this code does what you need. You can use any number of columns of data now. Hope this helps...
    Please Login or Register  to view this content.
    VBA With SheetName Columns.xlsm

  8. #8
    Registered User
    Join Date
    05-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    4

    Re: If sheet name equals range

    Thank you Marvin! This worked perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] If checkbox is checked copy cells from a sheet to another sheet if value equals to combobo
    By cyclodries in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2019, 07:21 AM
  2. [SOLVED] VBA If Cell Value equals, then copy a range, and paste to another sheet. Then next.
    By DM01 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-20-2018, 03:08 PM
  3. [SOLVED] If each cell in range equals 0 then clear contents of range and move to the next row
    By dagardner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2014, 08:44 PM
  4. [SOLVED] If Value in a range of cells equals X, then echo value (name) in another range of cell
    By tonytorero in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-03-2013, 06:23 PM
  5. Replies: 15
    Last Post: 06-27-2011, 08:58 PM
  6. If Range of Cells Equals Value
    By dreicer_Jarr in forum Excel General
    Replies: 1
    Last Post: 04-18-2010, 03:01 PM
  7. [SOLVED] if a:a (range) equals january and c:c equals gas then add g:g ($)
    By BCOz in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-29-2005, 03:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1