+ Reply to Thread
Results 1 to 2 of 2

Help to code not work on Sheet with many rows and columns.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Help to code not work on Sheet with many rows and columns.

    Hi I have below code. It was working on a test sheet but when i now try it on a very big file it give me an error.
    The code sort the rows in a chosen column. And add sheets with that name. So if in column Austria is there, it will create a sheet called Austria and put all rows with Austria in there. The File i am working with have 100 columns and 115806 rows. It give me this error message in the red field.

    ActiveSheet.Name = x

    The name is all ready taken try a new one.


    Please have a look i cant off course attach a so big file. But would be happy if some know and can help with that.

    Thanks in advance

    Sincerely

    Abjac

    Sub abjacz2()
    Dim rcell As Range, x As String, y As String
    Dim z As String
    y = InputBox("Please Enter The Column:  (Letter Designation)")
    z = InputBox("Enter the name of the start page, example sheet1")
    With Sheets(z)
    .Columns(y).Replace " ", "", xlPart
        For Each rcell In .Range(y & "3:" & y & .Range(y & Rows.Count).End(3).Row)
            If rcell.Value <> rcell.Offset(-1).Value Then
                x = rcell.Value
                Sheets.Add after:=Sheets(Sheets.Count)
                ActiveSheet.Name = x
                Sheets(x).Rows(1).Value = Sheets(z).Rows(1).Value
            .Range(y & "1:" & y & .Range(y & Rows.Count).End(3).Row).AutoFilter 1, x
            .Range(y & "2:" & y & .Range(y & Rows.Count).End(3).Row).SpecialCells(12).EntireRow.Copy Sheets(x).Range("A" & Rows.Count).End(3)(2)
            .AutoFilterMode = False
            End If
        Next rcell
    End With
    End Sub

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Help to code not work on Sheet with many rows and columns.

    try changing,
    Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Name = x
    to
    If Not Evaluate("ISREF('" & x & "'!A1)") Then Sheets.Add(, Sheets(Sheets.Count)).Name = x
    adds a new sheet with the x string value, if that sheet name doesn't exist already

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 05-30-2015, 03:12 PM
  2. VBA code to copy rows to another sheet and sumup its columns
    By patua in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2014, 11:59 AM
  3. [SOLVED] How to make the macro work for all rows in the work sheet
    By Valli nayaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 10:43 PM
  4. [SOLVED] Code to work on rows 9-220 only
    By Grf in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2012, 05:49 AM
  5. Copy rows from work sheets to combine to one work sheet based on cell value
    By joemcmillen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2008, 05:04 PM
  6. Replies: 4
    Last Post: 04-26-2007, 02:13 AM
  7. Replies: 2
    Last Post: 07-11-2006, 11:15 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1