Consulting

Results 1 to 12 of 12

Thread: If statement

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location

    If statement

    Wanted to know how I can have the following done only if there is a value in Column E. Basically, to have the formula only filled in up until there is no value in Column E.

    Thanks



    Range("I10").FormulaR1C1 = "=+RC[-5]/5280"
        Range("I10").Select
        Selection.AutoFill Destination:=Range("I10:I65536"), Type:=xlFillDefault

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by goldie12
    Wanted to know how I can have the following done only if there is a value in Column E. Basically, to have the formula only filled in up until there is no value in Column E.

    Thanks

    Range("I10").FormulaR1C1 = "=+RC[-5]/5280"
        Range("I10").Select
        Selection.AutoFill Destination:=Range("I10:I65536"), Type:=xlFillDefault

    With Range("I10")
        .FormulaR1C1 = "=RC[-5]/5280"
        .AutoFill Destination:=.Resize(Cells(Rows.Count, "E").End(xlUp).Row - 9), Type:=xlFillDefault
    End With
    But maybe you mean



    .FormulaR1C1 = "=RC[-4]/5280"
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    I get the following error message:

    Runtime error '1004'
    AutoFill method of Range Class failed

    and it points to:


    .AutoFill Destination:=.Resize(Cells(Rows.Count, "I").End(xlUp).Row - 9), Type:=xlFillDefault

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by goldie12
    I get the following error message:

    Runtime error '1004'
    AutoFill method of Range Class failed

    and it points to:


    .AutoFill Destination:=.Resize(Cells(Rows.Count, "I").End(xlUp).Row - 9), Type:=xlFillDefault
    I had corrected it, you obviously got it before I did. Try


    With Range("I10")
        .FormulaR1C1 = "=+RC[-5]/5280"
        .AutoFill Destination:=.Resize(Cells(Rows.Count, "E").End(xlUp).Row - 9), Type:=xlFillDefault
    End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Thanks I changed it and it worked fine.

    One more question:

    Wanted to know how I can have the following done only if there is a value in Column Row 9 Column. Basically, to have the formula only filled in to the right up until there is no value in Row 9 Column N.


    Range("N10:N16").Select 
       Selection.AutoFill Destination:=Range("N10:BN16"), Type:=xlFillDefault

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by goldie12
    Thanks I changed it and it worked fine.

    One more question:

    Wanted to know how I can have the following done only if there is a value in Column Row 9 Column. Basically, to have the formula only filled in to the right up until there is no value in Row 9 Column N.
    Same principle


    Dim iLastColumn As Long
        iLastColumn = Cells(9, Columns.Count).End(xlToLeft).Column
        If iLastColumn > 14 Then
            With Range("N10:N16")
                .AutoFill Destination:=.Resize(, iLastColumn - 13), Type:=xlFillDefault
            End With
        End If
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Thank you

    Can you use this same principle when assigning the seriescollection values for a chart?
    Example:

    As long as there is a value in Row 9 Column N, then the series is equal to Row 10 Column N all the way to the right.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by goldie12
    Thank you

    Can you use this same principle when assigning the seriescollection values for a chart?
    Example:

    As long as there is a value in Row 9 Column N, then the series is equal to Row 10 Column N all the way to the right.
    If you mean such as extending it with

    Worksheets(1).ChartObjects(1).Chart. _     SeriesCollection.Extend Worksheets(1).Range("c1:c10")
    then yes, same principle.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    I'm not sure that Extends will work, because the range is not definite.

    How about assigning the source data? What I have now is the user inputting this into an input box. I really don't want them to have to do this, but it is the only thing that I have come up with. Any suggestions?

    Example:

    The source data range will be:


    =Data!$K9:$K16,Data!$N9:$(This value will depend on the data range selected by the user, Basically I need an IF statement to say set this value depending on how far to the right the values go in Row 9 Column N to the right)16(This value will always be 16 because that is the ending value in the Row)

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by goldie12
    I'm not sure that Extends will work, because the range is not definite.

    How about assigning the source data? What I have now is the user inputting this into an input box. I really don't want them to have to do this, but it is the only thing that I have come up with. Any suggestions?

    Example:

    The source data range will be:


    =Data!$K9:$K16,Data!$N9

    :$(This value will depend on the data range selected by the user, Basically I need an IF statement to say set this value depending on how far to the right the values go in Row 9 Column N to the right)16(This value will always be 16 because that is the ending value in the Row)
    Anywhere a range is defined, you apply that principle, as it is just a way of determing an end point to the range.

    Why don't you try it and see. You won't learn anything if I just do it for you every time. Try it and post back your code when you reach a block.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Sub LastCellInRow() 
    Sheets("Data").Select 
    Static myDataRange As Range 
    Dim MyCell As String
    For i = 1 To 16 
    If [N9].Offset(0, i).Value = 0 Then 
    Else 
    MyCell = [N9].Offset(0, i).Address(rowabsolute:=False, columnabsolute:=False) 
    End If 
    Next i
    ActiveSheet.ChartObjects(1).Activate 
    ActiveChart.SetSourceData Source:=Sheets("Data").Range("K9:K16,N9:" & MyCell & 16), PlotBy:= _ 
    xlRows 
    End Sub

    This works, however, I am trying to include the following as the source data:
    =Data!$K$9:$K$16,Data!$N9:$whatever$16 this will always be row 16.
    Basically it is two ranges that need to be selected and the last part of the last range is dependant upon if there are values in Row 9, but it will always include up until row 16.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It doesn't look as though you have tried to implement the principle to me!

    Quote Originally Posted by goldie12
    Basically it is two ranges that need to be selected and the last part of the last range is dependant upon if there are values in Row 9, but it will always include up until row 16.
    What does this mean? Which part is the variable bit to test for? Of course, with your attempt it will probably be clearer.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •