Consulting

Results 1 to 16 of 16

Thread: Solved: check the A Cloumn and copy to aother sheet

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Question Solved: check the A Cloumn and copy to aother sheet

    I need a help , i have a list . that some items have not data on column A but they have data on column B and .... , I need a Macro code check if column A is blank copy their row to another sheet .

    Thank you so much .

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Air code

    [vba]

    With Activesheet

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row

    For i = 1 To lastrow

    If .Cells(i, "A").Value = "" Then

    nextrow = nextrow + 1

    .Rows(i).Copy Worksheets("Sheet2").Cells(nextrow, "A")
    End If
    Next i
    End With[/vba]
    ____________________________________________
    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 Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you but , it is not work .

  4. #4
    VBAX Regular
    Joined
    Mar 2012
    Posts
    12
    Location
    I think this should work for you

    [VBA]Dim i As Integer

    Dim x As Integer

    Dim lastrow As Integer

    With ActiveSheet

    lastrow = Range("B1").End(xlDown).row

    x = 1

    For i = 1 To lastrow
    If .Cells(i, 1).Value = "" Then
    .Rows(i).Copy
    Sheets("Sheet2").Rows(x).PasteSpecial (xlPasteAll)
    x = x + 1
    End If
    Next i
    End With

    End Sub[/VBA]

    -jonhaus

  5. #5
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you , and it is work now .

  6. #6
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Could you please helo me if i want to move or cut these data what can i do ?
    that mean will not be in sheet A .

  7. #7
    VBAX Regular
    Joined
    Mar 2012
    Posts
    12
    Location
    Glad to here it worked. Try something like this.


    [vba]

    Sub CopyRows()

    Dim i As Integer

    Dim x As Integer


    Dim lastrow As Integer


    With ActiveSheet

    lastrow = Range("B1").End(xlDown).row

    x = 1

    For i = 1 To
    lastrow
    If .Cells(i, 1).Value = "" Then

    .Rows(i).Copy

    Sheets("Sheet2").Rows(x).Insert Shift:=xlDown

    .Rows(i).Delete

    x = x + 1
    End If
    Next i
    End With


    End Sub
    [/vba]

  8. #8
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you but delete dose not work .

  9. #9
    VBAX Regular
    Joined
    Mar 2012
    Posts
    12
    Location
    Are you getting an error? I don't have any problem running it.

  10. #10
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    I run it but it does not delete .

  11. #11
    VBAX Regular
    Joined
    Mar 2012
    Posts
    12
    Location
    Give this a shot I forgot to account that for the cell locations changing when the row is deleted.

    [vba]

    Sub CopyRows()



    Dim x As Integer



    Dim lastrow As
    Integer



    With
    ActiveSheet


    x = 1


    Do Until Len(Cells(x, 2).Value) = 0
    If .Cells(x, 1).Value = "" Then



    .Rows(x).Copy



    Sheets("Sheet2").Rows(x).Insert
    Shift:=xlDown



    .Rows(x).Delete

    Else

    x = x + 1

    End If
    Loop

    End With


    End Sub

    [/vba]

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by jonhaus
    Give this a shot I forgot to account that for the cell locations changing when the row is deleted.
    The trick is to work-bottom up when deleting not top-down, then the cell locations do not change.
    ____________________________________________
    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

  13. #13
    VBAX Regular
    Joined
    Mar 2012
    Posts
    12
    Location
    Good idea! I have never thought of approaching it like that. I think my way will still work, but yours probably makes more since. Thanks.

  14. #14
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Exclamation

    I have Still the Problem with this code

    PHP Code:
    Sub CopyRows()     
        
    Dim x As Integer    
        Dim lastrow 
    As Integer 
        With ActiveSheet   
        x 

        
    Do Until Len(Cells(x2).Value) = 
            
    If .Cells(x1).Value "" Then 
             
    .Rows(x).Copy 
                Sheets
    ("Sheet2").Rows(x).Insert 
                Shift
    :=xlDown 
                
    .Rows(x).Delete      
            
    Else              
                
    1             
            End 
    If 
        
    Loop     
    End With 
    End Sub 

    1- This code will not copy to the first row of second sheet
    2- i have 765233 row and when run this code i got error on 32767 Record. and when click on debug show me this line x = x + 1 and in my mouse hint show x= 32767 .
    3- in there any other fast way ?

    Thank you . Please help me on this subject .

  15. #15
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    1) [VBA]Sheets("Sheet2").Rows(Sheets("Sheet2").Range(Cells.count,1).Row).Insert
    Shift
    :=xlDown[/VBA]
    2) [VBA]Dim x as Long[/VBA] (not Integer)
    3) at start of code insert:
    [VBA]Application.ScreenUpdating = False
    Application.DisplayAlerts = False[/VBA]
    and at the end of your code set them both back to true
    ------------------------------------------------
    Happy Coding my friends

  16. #16
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thanks to all . Now everything work fine .

Posting Permissions

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