+ Reply to Thread
Results 1 to 2 of 2

VBA Subordinate and Function That Replace Specific Elements in An Array

  1. #1
    Registered User
    Join Date
    10-27-2014
    Location
    Boulder, CO
    MS-Off Ver
    MS Excel 2013
    Posts
    1

    Question VBA Subordinate and Function That Replace Specific Elements in An Array

    Hello,

    I am looking for some help with VBA related questions I have to solve for homework assignment I have.

    I am asked to create a VBA subroutine that replaces all 1’s in an array (selection) with a 2 and all 2’s in an array with a 1.

    Then I am asked to do the same but using a function instead by doing this previous task and outputting it in a different array in a different selection (Ctrl+Shift+Enter).

    What I have so far is the following:

    First part)
    Please Login or Register  to view this content.
    For this part, I am not sure about the DataRange formula or that my method is correct regarding the For..Loop c's part.

    Second Part)
    Please Login or Register  to view this content.
    After the ReDim line, I kind of got stuck and didn't know what to do. I had For m and For n from 1 to nRows and nCols consequently; however, I didn't know how to include my conditions of swapping the values of 1 and 2 and outputting that in the array B().

    Thank you,
    HanadiS
    Last edited by Leith Ross; 10-27-2014 at 10:22 PM. Reason: Added Code Tags

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: VBA Subordinate and Function That Replace Specific Elements in An Array

    The way you have your first part set up, DataRange is going to refer to a single cell within your selection. You're also taking some unnecessary steps. Another problem is your If statements. The first IF will convert 1s to 2s, but the second will convert them right back to 1s. The following will accomplish what you want.

    Please Login or Register  to view this content.
    Start with that and see if you can go from there (you wouldn't want me doing all your homework, would you)
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

+ 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] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  2. help assigning elements of dictionary to array and then pasting array into worksheet
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-05-2013, 10:37 AM
  3. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 AM
  4. Refer to specific elements in an array
    By MCCCLXXXV in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2009, 02:31 PM
  5. Transpose Function not Working with Long Array Elements
    By Ngan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2005, 08:05 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