Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 34 of 34

Thread: delete

  1. #21
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi
    this works great i am sorry
    i was not in the office to thank you properly

    i have one more question
    if i do not want to delete the rows if i want to copy them to another sheet

    starting at "A1"


    thanks
    Quote Originally Posted by mdmackillop
    Try this
    [vba]
    Option Explicit
    Sub DelChars()
    Dim rng As Range, i As Long
    Dim RegExp
    Set RegExp = CreateObject("VBScript.RegExp")
    With RegExp
    .Global = True
    .IgnoreCase = True
    End With
    RegExp.Pattern = "\w"
    Set rng = Intersect(Columns(2), ActiveSheet.UsedRange)
    For i = rng.Cells.Count To 1 Step -1
    If Not (RegExp.test(rng(i))) Then rng(i).EntireRow.Delete
    Next
    End Sub
    [/vba]

  2. #22
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    i forgot
    what i need to change in the macro in to answer the question in my prewios post

    thanks

  3. #23
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Record a macro copying and pasting to a new location. Substitute this for the Delete command. If you have problems, post your code.
    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'

  4. #24
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi

    it does not work
    it says that the data is in different shape

    the code:

    [VBA]Sub DelChars2()
    Dim rng As Range, i As Long
    Dim RegExp
    Set RegExp = CreateObject("VBScript.RegExp")
    With RegExp
    .Global = True
    .IgnoreCase = True
    End With
    RegExp.Pattern = "(mm)"
    Set rng = Intersect(Columns(2), ActiveSheet.Range("B2:B6"))
    For i = rng.Cells.Count To 1 Step -1
    If (RegExp.test(rng(i))) Then rng(i).EntireRow.Copy


    Sheets("Sheet3").Select
    Rows("72:72").Select
    ActiveSheet.Paste
    Next
    End Sub
    [/VBA]

    thnaks

  5. #25
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Try stepping though the code to identify the problem.
    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'

  6. #26
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    I am sorry

    i am not succeeding

  7. #27
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    macro work

    hi

    i have a question why the attached macro does not work

    [VBA]Sub DelChars2()
    Dim rng As Range, i As Long, b As Integer
    Dim RegExp
    Set RegExp = CreateObject("VBScript.RegExp")
    With RegExp
    .Global = True
    .IgnoreCase = True
    End With
    RegExp.Pattern = "(mm)"
    Set rng = Intersect(Columns(2), ActiveSheet.Range("B1:B10"))

    For i = rng.Cells.Count To 1 Step -1
    If (RegExp.test(rng(i))) Then rng(i).EntireRow.Copy


    Sheets("Sheet3").Select
    Sheets("sheet3").Range("a80").pastespetial

    Sheets("Sheet1").Select

    Next
    End Sub[/VBA]

    thanks

  8. #28
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Oleg,

    Please stay with your first thread at http://www.vbaexpress.com/forum/show...t=31447&page=2

    Imagine if you were answering questions only to find out others were answering the same question in another thread. Does that make sense?

    Mark

  9. #29
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    I did not know what to do my old thread was mark as "solved"

    only because of that

    sorry without knowing

  10. #30
    VBAX Regular mikke3141's Avatar
    Joined
    Jun 2007
    Location
    Klaukkala
    Posts
    53
    Location
    I got it work when i changed pastespetial to pastespecial

  11. #31
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    it still
    gives me an error when i want to run the macro several times and when i clean sheet3

  12. #32
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    There is a simple error here. Try and work out the logic of what is happening
    [VBA]
    For i = rng.Cells.Count To 1 Step -1
    If (RegExp.test(rng(i))) Then rng(i).EntireRow.Copy
    Sheets("Sheet3").Select
    Sheets("sheet3").Range("a80").pastespecial
    Sheets("Sheet1").Select
    Next
    [/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'

  13. #33
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    i am trying but without success

  14. #34
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    Does this not make more sense

    [vba]
    x = 80
    For i = rng.Cells.Count To 1 Step -1
    If (RegExp.test(rng(i))) Then
    rng(i).EntireRow.Copy
    Sheets("Sheet3").Range("a" & x).pastespecial
    x = x+1
    end if
    Next
    [/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
  •