+ Reply to Thread
Results 1 to 9 of 9

Macro For Dividing a Named Range by 10

  1. #1
    Registered User
    Join Date
    04-19-2010
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    85

    Macro For Dividing a Named Range by 10

    Hi All

    I am hoping that someone would help me with some code.

    I have a named range called TempData and the reference used is =OFFSET(TestData!$C$2,0,0,COUNT(TestData!$C:$C),12).

    I would like to use a macro to divide each individual cell within this range by 10, but only the once. Then the macro will recognise the operation has been completed and will not calculate again.

    Many thanks



    Diane

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro For Dividing a Named Range by 10

    Hi Diane,

    You may be able to do what you want manually in Excel:
    a. Put 10 in an empty cell that is not in your 'TestData' range.
    b. Copy that cell (either CTRL C or Edit > Copy).
    c. Select the range you want to divide by 10 (Highlight the range with the mouse).
    d. Edit > PasteSpecial. Select 'Values' and 'Divide' (both selected at the same time), then click on 'OK'.
    e. Manual range division is complete.

    I have a named range called TempData and the reference used is =OFFSET(TestData!$C$2,0,0,COUNT(TestData!$C:$C),12).
    I had problems with 'COUNT(TestData!$C:$C)'. It always returned a value of 0 for me. I assumed you wanted all the rows in the range that are in Column C.

    I would like to use a macro to divide each individual cell within this range by 10, but only the once. Then the macro will recognise the operation has been completed and will not calculate again.
    There are two Macros that follow:
    a. The first divides all non-zero cells in the entire 'TestData' range by 10.
    b. The second divides all non-zero cells in the 'TestData' range by 10 starting at cell 'C2' for all rows in the range (row 2 thru n) and for exactly 12 columns.

    In order to do this only once I had to borrow a cell (I arbitrarily selected 'A24') in your worksheet to act as a flag to indicate whether or not the division had taken place.

    There are instructions in the Macros on what to modify if you want to:
    a. Change the flag sentinel cell.
    b. Hide the flag sentinel cell.
    c. Change the number of columns or starting column.
    d. Change the number of rows or starting row.

    Lewis
    Please Login or Register  to view this content.
    Last edited by LJMetzger; 01-23-2014 at 09:30 AM. Reason: Deleted bad line in DivideContentsOfPartOfNamedRangeByTenOnlyOnce() - 'dim iColumnCount as Integer' (duplicate declaration)

  3. #3
    Registered User
    Join Date
    04-19-2010
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Macro For Dividing a Named Range by 10

    Morning Lewis

    I seem to be having an error message with the first code...... Compile Error: Duplicate Declaration in Current Scope (highlighted Dim iColumnCount As Integer)

    Thanks


    Diane

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro For Dividing a Named Range by 10

    Sorry, when I was adding comments, I did not test the program again.

    Please delete the following line or copy the code again (I deleted the bad line in post #2).
    Please Login or Register  to view this content.
    Lewis

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Macro For Dividing a Named Range by 10

    Quote Originally Posted by LJMetzger View Post
    I had problems with 'COUNT(TestData!$C:$C)'. It always returned a value of 0 for me.
    Perhaps you only had text in column C? COUNT will only count numbers (COUNTA will count both).
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro For Dividing a Named Range by 10

    Hi Izandol,

    Thanks for taking a look at my problem.

    It was my lack of formula knowledge. The User had a range named 'TestData' and I probably assumed wrongly that the 'TestData' in the formula:
    Please Login or Register  to view this content.
    referred to the 'Range'. It is probably a SHEET REFERENCE, and my Sheet has a different name. When I removed the 'TestData' from the formula, the COUNT function worked, as all the cells were numeric.

    Lewis
    Last edited by LJMetzger; 01-23-2014 at 12:25 PM. Reason: Changed 'File Reference' to 'Sheet Reference'

  7. #7
    Registered User
    Join Date
    04-19-2010
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Macro For Dividing a Named Range by 10

    Temperature Graph Draft.xlsm

    Hi Lewis,

    I am having trouble implementing the code. I have attached a shortened version of the workbook, and appologise in advance if I have been doing something wrong.

    Kindest regards always


    Di

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro For Dividing a Named Range by 10

    Sorry again Diane,

    It is all my fault. Lewis can't read. He got confused between your Sheet 'TestData' and your range 'TempData'. Try the following Macro, which I tested on your sample workbook. In the future, it's always easier for the solvers, if you provide a sample workbook, so they can test what they're doing on your data.

    Sorry again.

    Lewis

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-19-2010
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Macro For Dividing a Named Range by 10

    Hi Lewis

    Thats perfect......

    My fault I should have explained it a little better....I will add a sample in future, but hopefully this little project will be finished.

    Thanks

    Di

+ 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. excel macro range define to another sheet / named range
    By koi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 10:25 AM
  2. [SOLVED] Determine what Named Range the Target Address is and return Named Range Name
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2012, 10:49 PM
  3. Replies: 3
    Last Post: 06-04-2011, 10:56 AM
  4. Macro code to change cell range to named range
    By Orlic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2008, 11:51 AM
  5. Update range:How do I edit a Named Range using macro's
    By Tom Ogilvy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-06-2005, 06: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