+ Reply to Thread
Results 1 to 4 of 4

Compile Error

  1. #1
    Registered User
    Join Date
    07-12-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Lightbulb Compile Error

    Capture.JPGHello Friend I am trying to create a Macro where while tesiting i am getting the below compile Error.

    Column B is Employee Name
    Column E is the Project Details (A, B, C, D)
    Column G, H, I, J, K Are the expense (Airport Tax, Hotel , Fare, Other)

    I wanted to copy these details in the Sheets Name based on Projects (A, B, C, D)

    I have attached the IMAGE



    Below is the Macro

    Please Login or Register  to view this content.
    Sub traveldtls()

    Dim ws As Worksheet
    Dim lastrow As Long
    Dim i As Integer
    Dim expdtls1 As Integer
    Dim expdtls2 As Integer
    Dim EMPname As String

    lastrow = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row


    For i = 2 To lastrow

    If Cells(i, 5) = "A" Then
    Range(Cells(i, 2), Cells(i, 6), Cells(i, 7)).Select
    Sheets(2).Range(Cells(4, 6), Cells(4, 7), Cells(4, 7)).PasteSpecial

    End If
    Next i


    End Sub
    Please Login or Register  to view this content.
    Last edited by akash kothari; 09-23-2014 at 04:38 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: Compile Error

    The .Select should be .Copy


    Please add Code Tags to your post.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-12-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Compile Error

    Hi TMS

    Thank you for your quick reply

    But still below code throws and Compile error

    Range(Cells(i, 2), Cells(i, 6), Cells(i, 7)).Copy

    Akash

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Compile Error

    The range object can only take 2 arguments, a row and a column. Remove one of the cells or use union instead.
    Last edited by AB33; 09-23-2014 at 05:05 AM.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,342

    Re: Compile Error

    @AB33: ah, good spot ... I went for the obvious without looking closely at the range. Strictly speaking, it's not row and column, it's start and end cells. And it could be one parameter if the string is a text string with a valid cell or range address.

    That said, the PasteSpecial won't work either, same reason. And I note that two of the cell addresses are the same. And, being picky, this loop is just going to keep overwriting the same cell(s).

    You could have something like this, which will compile but maybe won't do what you want:

    Please Login or Register  to view this content.

    Regards, TMS

  6. #6
    Registered User
    Join Date
    07-12-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Compile Error

    Ok, I got this; But this Macro is not giving me the output as i was expecting.
    will you be able to assist on this?

    Akash

+ 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. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  2. [SOLVED] Compile Error in Hidden Module and Compile Error: Can't find project or library
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2013, 07:03 PM
  3. [SOLVED] Compile error: Constant expression required error when merging two Codes
    By Kezwick in forum Outlook Programming / VBA / Macros
    Replies: 8
    Last Post: 06-26-2013, 09:32 AM
  4. compile error: compile error expected
    By odeno in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2008, 04:30 PM
  5. VBAProject name compile error, not defined at compile time
    By Matthew Dodds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2005, 03:20 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