Copying column in excel (1 Viewer)

ianverrier

New member
Local time
Today, 02:17
Joined
Dec 20, 2010
Messages
3
I wrote the following code in visual basic to copy column C to column IH in an excel worksheet but I get this error when trying to select column C:


Run-time error '1004':

Select method of Range class failed



Sub TestExceladfd(current_path, rnc As String) 'subroutine copies the utancell field in the utrancell worksheet to field IH
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim strPathAndFileName As String

Const xlToLeft As Long = -4159

Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
strPathAndFileName = current_path & "\input_files\" & rnc & ".xls"

Set xlWB = objXL.Workbooks.Open(strPathAndFileName)

Set xlWS = xlWB.Worksheets("UtranCell")




xlWS.Columns("C").Select '*** fails here
objXL.Selection.Copy


xlWS.Columns("IH").Select


objXL.ActiveSheet.Paste



xlWB.Save
xlWB.Close
objXL.Quit

Set objXL = Nothing


End Sub


Strange thing is I believe this same code worked before.

Any ideas?

Ian
 

SpentGeezer

Pure Noobism
Local time
Today, 19:17
Joined
Sep 16, 2010
Messages
258
I tested your sub on my PC (Acc 2003) and it worked fine.
 

Users who are viewing this thread

Top Bottom