Consulting

Results 1 to 2 of 2

Thread: run time error '1004' Help!!!!

  1. #1
    VBAX Newbie
    Joined
    Apr 2016
    Location
    blackpool
    Posts
    1
    Location

    run time error '1004' Help!!!!

    Hello,

    can anyone help me figure out why I am getting this message:
    "run time error '1004' application-defined or object-defined error"

    the problem line where is shows the error is:

    range("A1").select
    and here is all of the code:

    Sub HorizontalLoop()
    Dim lCol As Long
    Sheets("output").Select
    
    For lCol = 1 To 100
    Dim inputrange As String
    If Not IsEmpty(Cells(lCol).Value) Then
    inputrange = Cells(1, lCol).ValueActiveCell.EntireColumn.Select
    Selection.Copy
    Sheets("input").Select
    range("A1").Select
    ActiveSheet.Paste
    Sheets("output").Select
    
    End If
    
    Next lCol
    End Sub
    any help is much appreciated
    Thanks
    H

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,734
    Location
    I think there were some copy/paste errors

    try something like this

    Usually you don't need to .Select something to use or act on it

    Option Explicit
    Sub HorizontalLoop()
    
        Dim lCol As Long
        Dim inputrange As String
        
        Sheets("output").Select
         
        For lCol = 1 To 100
            If Not IsEmpty(Cells(1, lCol).Value) Then   '   Row 1  ?????
                'assuming that 2 lines were accidently joined, and they should have been
                'inputrange = Cells(1, lCol).Value
                'ActiveCell.EntireColumn.Select
                
                'this does it from 'output' to 'input' which seems backwards to me
                Columns(lCol).Copy Sheets("input").Columns(lCol)
            End If
             
        Next lCol
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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