+ Reply to Thread
Results 1 to 17 of 17

Entering a formula depending on criteria of cell

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Entering a formula depending on criteria of cell

    1) You don't need to both exit the sub if the target.cells.count > 1 and do a FOR/NEXT loop on all the cells in the target...one or the other. I usually leave in the FOR/NEXT loop and remove the target.cells.count > 1 code as unneeded.

    2) No clue about the rest of that, not part of this current topic.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  2. #2
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Entering a formula depending on criteria of cell

    Sorry a bit of a newwbie to this,

    I have tried taking out the target.cells.count > 1 code but still not working.

    The orginal formula works fine, just does not want to work within the exsiting code or understand the array... ??

    G

  3. #3
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Entering a formula depending on criteria of cell

    This formula works great but as i said, my formula is an array, so i just cant enter it in. I have looked throught the internet on how to do this but they expect the formulaarray to follow a range.

    I dont see the point in reposting this as a different question as it is part of the same problem. as its a formula i need to insert into a cell depending on a certain criteria

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    Application.EnableEvents = False
    
        For Each cell In Target
            If Not Intersect(cell, Range("A2:A10000")) Is Nothing Then _
                Cells(cell.Row, "D") = "formula"
        Next cell
    
    Application.EnableEvents = True
    End Sub
    Would like to say thanks to all that have help, I know you have better things to do than help us newwbies lol

    cheers you are all stars

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Entering a formula depending on criteria of cell

    Adapting JB's code a little, something along these lines? I don't understand your previous code because it seems to contradict itself.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim cell As Range
    Application.EnableEvents = False
    
        For Each cell In Target
            If Not Intersect(cell, Range("A2:A10000")) Is Nothing Then _
                Cells(cell.Row, "D").FormulaArray = "=SUM(A1:A10)"
        Next cell
    
    Application.EnableEvents = True
    
    End Sub
    I know you have better things to do than help us newwbies lol
    Not at all, it is the raison d'etre of this place and places like it.

  5. #5
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Entering a formula depending on criteria of cell

    Strange thing is i tried adding .formulaArray and it came up with errors.

    the code which is contridicting it self is explained like this

    I already have this code on my worksheet

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    
    If Intersect(Target, Range("F2:f3000,g2:g3000,h2:I3000,l2:l3000,m2:m3000,n2:n3000,o2:o3000")) Is Nothing Then Exit Sub
    If Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    If Application.WorksheetFunction.IsText(Target.Value) Then
    Target.Value = UCase(Target.Value)
    
    
    End If
    Application.EnableEvents = True
    
    End Sub
    and what im trying to do if this code works

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim cell As Range
    Application.EnableEvents = False
    
        For Each cell In Target
            If Not Intersect(cell, Range("A2:A10000")) Is Nothing Then _
                Cells(cell.Row, "D").FormulaArray = "=SUM(A1:A10)"
        Next cell
    
    Application.EnableEvents = True
    
    End Sub
    is to try and to put the two together

    G

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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