PDA

View Full Version : run time error '1004' Help!!!!



HushHoney
04-05-2016, 07:24 AM
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

Paul_Hossler
04-05-2016, 08:21 AM
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