Results 1 to 9 of 9

Pulling Range of Cell Values Based on another Cell's Value

Threaded View

  1. #1
    Registered User
    Join Date
    01-14-2012
    Location
    Arizona, United States
    MS-Off Ver
    Excel 2000
    Posts
    16

    Pulling Range of Cell Values Based on another Cell's Value

    I am new to using Macros in excel. I am trying to figure out how to pull a range of cell values into different range of cells. The cell values pulled will depend on the value of another cell. Below is an example of code I made to pull the cells using multiple lines of code.

    Sub CopyRange()
    
    If Range("Q2").Value = "A" Then
    Range("R2").Value = Range("A2")
    Range("S2").Value = Range("B2")
    Range("R3").Value = Range("A3")
    Range("S3").Value = Range("B3")
    Range("R4").Value = Range("A4")
    Range("S4").Value = Range("B4")
    Range("R5").Value = Range("A5")
    Range("S5").Value = Range("B5")
    End If
    
    If Range("Q2").Value = "B" Then
    Range("R2").Value = Range("C2")
    Range("S2").Value = Range("D2")
    Range("R3").Value = Range("C3")
    Range("S3").Value = Range("D3")
    Range("R4").Value = Range("C4")
    Range("S4").Value = Range("D4")
    Range("R5").Value = Range("C5")
    Range("S5").Value = Range("D5")
    End If
    
    End Sub

    Is there a way I can do it in fewer lines of code? For example I tried writing it like shown below and it did not work:

    If Range("Q2").Value = "A" Then
    Range("R2:S5").Value = Range("A2:B5")

    Also, would it be possible to pull values from A2:B5 on Sheet2 into cells R2:S5 on Sheet1?

    Thanks in advance for the help!
    Last edited by Freek; 01-13-2021 at 10:28 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Return values to specific columns based on range of cell values
    By sbrt10 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-27-2019, 03:15 AM
  2. [SOLVED] Pulling row data to new worksheet based on values on row cell
    By afrazier25 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-26-2015, 02:50 PM
  3. Sum cells in a range based between two equal cell values in another range
    By sshone1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-09-2013, 08:12 AM
  4. Need help making a macro to copy range of values based on cell values.
    By zolton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2013, 08:58 AM
  5. Pulling a Specific Cell when Pulling a Tabel from Web Based Data
    By Zallen89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2013, 05:39 PM
  6. Range Based on Cell Values
    By Clark in forum Excel General
    Replies: 2
    Last Post: 05-06-2009, 02:56 AM
  7. [SOLVED] formula for named cell/range based on cell values
    By alex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2005, 10:05 AM

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