+ Reply to Thread
Results 1 to 4 of 4

Syntax of formula with variable within macro.

  1. #1
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Lightbulb Syntax of formula with variable within macro.

    Hi Guys,

    I have a macro that is inserting a rows then populating them with data.

    In the macro a variable (rw) has been set with the row number of the newly inserted row.

    What I would like to do:-

    Get the existing macro to insert a formula to count how many cells in row rw from column F to DD are populated.


    So, when the macro is played this time it would read:-

    .Cells(rw, 4).Value = COUNTIF(F108:DD108,">0").Value

    And next time

    .Cells(rw, 4).Value = COUNTIF(F109:DD109,">0").Value

    So, what I am after is the correct syntax for:-

    .Cells(rw, 4).Value = COUNTIF(Frw:DDrw,">0").Value

    Any help would be greatly appreciated,

    Keith

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Syntax of formula with variable within macro.

    May be use a named range to store the range and access the named range via code


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Re: Syntax of formula with variable within macro.

    Thanks for your reply Sixthsense, unfortunately I don’t understand Excel or VBA well enough to be able to do this.

    All that I have got has been built using modified snippets from other users, then trying to learn from these snippets and modifying them for use elsewhere.

    Could you please elaborate using the above example?

    TIA
    Keith

  4. #4
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Re: Syntax of formula with variable within macro.

    Ok, I have now created another variable called RowRange

    RowRange = "F" & rw & ":" & "DD" & rw this evaluates to F108:DD108 which is the correct range.

    I have then tried all sorts of combinations of:-

    .Cells(rw, 4).Value = "=" & CountIf(RowRange > 0)
    .Cells(rw, 4).Value = "=" & Evaluate(CountIf(RowRange > 0))
    .Cells(rw, 4).Value = "=" & Evaluate("CountIf(RowRange > 0"))
    .Cells(rw, 4).Value = "=" & Evaluate CountIf(RowRange > 0

    but I am still up against a brick wall.

    Could someone please advise on the correct syntax, or I am approaching this the correct way even.

    TIA
    Keith

+ 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. Correct syntax to add a workbook name that is stored in a variable into a formula
    By lordterrin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2014, 03:46 PM
  2. syntax for value of a variable containing address in formula
    By Dewy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2010, 12:57 PM
  3. Hyperlink variable in formula syntax
    By LeeHa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-01-2008, 08:41 AM
  4. [SOLVED] Variable for Worksheet Name & Syntax for use in formula
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2006, 07:20 PM
  5. syntax when using a variable in a formula
    By anny in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2006, 11:15 AM

Tags for this Thread

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