Consulting

Results 1 to 13 of 13

Thread: Solved: Error on VBA Code in 600000 Row

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

    Exclamation Solved: Error on VBA Code in 600000 Row

    i have a file with 600000 Row and i use this code

    [vba]
    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

    [/vba]
    This code will copy only the row that their B column have a data to Sheet 2

    but it is work till 32000 row after that runtime error and in debug show

    x = x + 1

    how can fix this problem ?

    Thank you .
    Last edited by Aussiebear; 04-02-2012 at 02:46 PM. Reason: adjusted the code tags for the correct usage

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Does the data end here, or do you have a break in the data at this point?

    Your last row is determined by looking down from row 1 whereas it should be looking up from the bottom of the sheet.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    I do not have a break in te data .

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    1. How are I and lastrow Dim-ed?

    It looks like they should be Long

    2. You were inconsistant with how you were refering to the ActiveSheet


    [vba]
    With ActiveSheet

    lastrow = .Range("B1").End(xlDown).Row Need the dot

    x = 1

    For i = 1 To lastrow
    If .Cells(i, 1).Value = "" Then This refers to Column A. Did you want .Cells(i,2) for Col B?
    .Rows(i).Copy
    Sheets("Sheet2").Rows(x).PasteSpecial (xlPasteAll)
    x = x + 1
    End If
    Next i
    End With
    [/vba]

    Paul

  5. #5
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    try:

    [vba]lastrow = .Range("B65536").End(xlUp).Row[/vba]
    ------------------------------------------------
    Happy Coding my friends

  6. #6
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    I user Dim lastrow As Long and on record 32768 I got this error :

    and when click on debug show me

    x = x + 1 and in hint show me x = 32768

    Run-time error '6' :

    Overflow

  7. #7
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Quote Originally Posted by CatDaddy
    try:

    [vba]lastrow = .Range("B65536").End(xlUp).Row[/vba]
    When use this code it will not copy to sheet2 . that mean does not work

    Thank you again .

  8. #8
    This went past 32768 without erroring.

    [vba]
    Sub TryThisCodeB()
    With ActiveSheet
    Dim lastrow As Double
    Dim x As Double, i As Double
    Application.ScreenUpdating = False
    lastrow = .Cells(Rows.Count, 2).End(xlUp).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
    Application.CutCopyMode = False
    Sheets("Sheet2").Select
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    Last edited by Aussiebear; 04-04-2012 at 03:52 PM. Reason: Corrected the tags surrounding the submitted code

  9. #9
    This might do the same thing but faster.

    [vba]
    Sub TryThisCodeC()
    Dim LR As Double
    LR = Cells(Rows.Count, 2).End(xlUp).Row
    With Range("A1:A" & LR)
    .SpecialCells(xlCellTypeBlanks).EntireRow.Copy Sheets("Sheet2").Range("A1")
    End With
    End Sub
    [/vba]
    Last edited by Aussiebear; 04-04-2012 at 03:48 PM. Reason: Corrected the tags surrounding the submitted code

  10. #10
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    I user Dim lastrow As Long and on record 32768 I got this error :

    and when click on debug show me

    x = x + 1 and in hint show me x = 32768

    Run-time error '6' :

    Overflow
    check data type of variable "x"

    that must be integer change it into long data type

    maximum value for integer data type is 32767

  11. #11
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thanks to all people , Now it is ok .

  12. #12
    For the sake of us when encountering the same problem, what was your solution?

  13. #13
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    I Use im x As Long

    and my problem sloved .

Posting Permissions

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