+ Reply to Thread
Results 1 to 6 of 6

[Bugs] Auto fill in new sheet using for loop in VBA

  1. #1
    Registered User
    Join Date
    01-22-2020
    Location
    HK
    MS-Off Ver
    Office365
    Posts
    7

    [Bugs] Auto fill in new sheet using for loop in VBA

    Hi Experts,
    I've tried for hours and it keeps showing error message.
    Could some one point out the bugs?

    Screenscap 1 - Adding Column D as index for lookup
    Capture1.PNG

    Screenscap 2 - The result I'd like to have
    Capture.PNG

    Attachment TXT - Macro that has bus
    Attachment XLSX - Raw data to work on

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: [Bugs] Auto fill in new sheet using for loop in VBA

    Try:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 01-23-2020 at 03:44 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Another demonstration …


    According to your attachment a VBA starter demonstration which assumes dates are from F1 to last column - so expandable as you wish - and
    uses 'Promo' as destination worksheet (if already exists, data are cleared, if not the 'Promo' worksheet is created) :

    PHP Code: 
    Sub Demo1()
          Const 
    "Promo"
            
    Dim CDU&, R&, L&
        
    With Sheet1.UsedRange
                
    If .Columns.Count 6 Then Beep: Exit Sub
                C 
    Evaluate("ROW(6:" & .Columns.Count ")")
                
    Application.Index(.Rows(1).Value, , C)
                
    UBound(C)
                
    2
                Application
    .ScreenUpdating False
            
    If Evaluate("ISREF('" "'!A1)"Then
                Sheets
    (P).UsedRange.Offset(1).Clear
                Sheets
    (P).Select
            
    Else
                
    Sheets.Add(, .Parent).Name P
                
    [A1:E1].Value2 Split("Date,SKUs,Customer,Regular $," " $"",")
            
    End If
            For 
    2 To .Rows.Count
                Cells
    (R1).Resize(U).Value D
                Cells
    (R2).Resize(U3).Value2 Application.Index(.Rows(L), , [{1,3,5}])
                
    Cells(R5).Resize(U).Value2 Application.Index(.Rows(L), , C)
                
    U
            Next
                Application
    .ScreenUpdating True
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 01-23-2020 at 07:58 PM. Reason: little tweak …

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: [Bugs] Auto fill in new sheet using for loop in VBA

    Hello kimfung20,

    Welcome to the forum!

    Here is another method. This macro looks for the first date in the header row and assumes all columns after that are dates. This allows you expand the dates as far as you need. The macro uses the two sheets in the workbook. None are renamed or added as in your original macro. The data on the "Sheet2" is cleared each time the macro is run. There is an added button on the worksheet to run the macro.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    01-22-2020
    Location
    HK
    MS-Off Ver
    Office365
    Posts
    7

    Re: [Bugs] Auto fill in new sheet using for loop in VBA

    Thanks for your help!

  6. #6
    Registered User
    Join Date
    01-22-2020
    Location
    HK
    MS-Off Ver
    Office365
    Posts
    7

    Re: Hi ! Another demonstration …

    Thankyou!

+ 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: 5
    Last Post: 11-17-2017, 04:43 PM
  2. Auto fill Log sheet from Negative values found on another sheet.
    By MrKingisin in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-12-2016, 06:41 PM
  3. Auto-Fill Or Auto-Copy A Newly-Added Row To A Different Row (Same Sheet)
    By miemhaiii in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-01-2014, 06:27 PM
  4. Auto fill static cell on separate sheet based on changing cells in another sheet
    By lawrence24 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-15-2014, 12:31 PM
  5. [SOLVED] Create loop to fill in sheet
    By keis386 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2014, 03:49 AM
  6. [SOLVED] Create new sheet from template, auto fill from index sheet and hyperlink
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2013, 04:57 AM
  7. Replies: 3
    Last Post: 05-27-2010, 10:57 AM

Tags for this Thread

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