Consulting

Results 1 to 13 of 13

Thread: offset and vba

  1. #1

    offset and vba

    can any one suggest how i a can select a cell which is offset (-1,3) and select that cell and the 3 cells to the right and clear any formula from them.
    what i have (and it will not work is)

    if offset(-1,3). select then
    .clear
    endif

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]ActiveCell.Offset(-1, 3).Range("A11").ClearContents[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Quote Originally Posted by mdmackillop
    [vba]ActiveCell.Offset(-1, 3).Range("A11").ClearContents[/vba]
    unfortunately it dose not help, i should have included a work book. sample attached.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your code needs to be run from a specific cell. Which cell is it?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Quote Originally Posted by mdmackillop
    Your code needs to be run from a specific cell. Which cell is it?
    each time a new row is appended the cell in colum "A" is selected, that is why i am looking at "offset" for a means to an end

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Cell changes are changing "Target" cells. Can you state what should happen when you insert a new value in Cell A20 as per your example.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Quote Originally Posted by mdmackillop
    Cell changes are changing "Target" cells. Can you state what should happen when you insert a new value in Cell A20 as per your example.
    in "A20" place any whole number "B20" input an value from worksheet "eanretail" "E20" will then fill with a value atomatically and the next line will appear with all the formula's from the previous row.

    what i want to do is select cell "E20" an input a value not in "eanretail", having selected cells "F20:H20,E21:F21" and cleared any formatting.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'm not clear on the formatting you wish to clear. This will colour the range of cells you appear you wish to clear.
    [VBA]
    '//select column B in the new row for next entry
    Range("A" & Target.Row + 1).Select 'B
    Changed = False
    '//Formatting code
    Dim r As Range
    Set r = Union(Target.Offset(, 1).Range("A1:C1"), Target.Offset(1).Range("A1:B1"))
    r.Interior.ColorIndex = 6
    End If
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    I'm also a bit uncertain of what you're trying to clear, but this clears formats
    [vba]
    Option Explicit

    Sub SelectIt()
    If Not ActiveCell.Row = 1 Then Range(ActiveCell.Offset(-1, 3), _
    ActiveCell.Offset(-1, 6)).ClearFormats
    End Sub
    [/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  10. #10
    please see the attached i might explain what i would like to achieve better.
    To all who have contributed i would like to thank them for their help and hope i have not missled thenm to much

  11. #11
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    To just clear the formula, use [VBA]Sub SelectIt()
    If Not ActiveCell.Row = 1 Then
    With Range(ActiveCell.Offset(-1, 3), ActiveCell.Offset(-1, 6))
    .Value = .Value
    End With
    End If
    End Sub[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  12. #12
    thanks to all who tried to help me in my hour of need, unfortunately nothing seemed to work, even with your help.
    i am now looking at a different way to accomplish what i wanted to do (it is comming along). I will post the results once i have finnished it.
    thanks to all once again

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You mix up clear formulas with clear formatting, which is very confusing.
    You can simplify things by writing the formula into colum E when you add the description, then there is no need to copy down, or to clear when the column E value is changed.
    [VBA]
    ActiveCell.Offset(, 1).FormulaR1C1 = _
    "=IF(ISERROR(VLOOKUP(RC[-3],eanretail!R3C1:R2058C3,3,FALSE))" & _
    ","""",VLOOKUP(RC[-3],eanretail!R3C1:R2058C3,3,FALSE))"

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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