View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Help to correct code

I need to make a correction, instead of Master.xls in each of the formulas
it should be PrepareTest.xls.
Sorry

"Pat" wrote in message
...
Sorry for the vagueness of my question.

The code is placed in a workbook called PrepareTest.xls

I am trying to filldown the following formulas which are on the first row.
The filling down must stop when there is no more data to display in column

A

='[Master.xls]PL'!$D8 contained in A1
='[Master.xls]PL'!$E8 contained in B1
='[Master.xls]PL'!$F8 contained in C1
='[Master.xls]PL'!$G8 contained in D1
='[Master.xls]PL'!$H8 contained in E1
='[Master.xls]PL'!$I8 contained in F1
='[Master.xls]PL'!$J8 contained in G1

Then I want to save the workbook as a .CSV file

Hope you understand what I am trying to do.


"Bob Phillips" wrote in message
...
I think it might help if you give us a hint as to what is going on or

not
as
the case may be, rather than leave us to work it out.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pat" wrote in message
...
Could someone let me know what is wrong with the following two pieces

of
code?

Private Sub Test_Click()
Dim LastRow As Long
Dim FirstRow As Long
Dim StartRange As Range

'Find end of data in col A in Sheet1
LastRow = LastDataRow(ThisWorkbook.Sheets("Sheet1").Range("A :A"))
With ThisWorkbook.Sheets("Sheet1")
'Find start of data based on reference in Sheet1 A1
FirstRow = Range(.[A1].Formula).Row
Set StartRange = .Range("A1:G1")
End With
StartRange.Resize(LastRow - FirstRow + 1).FillDown
Calculate
ThisWorkbook.Sheets("Sheet1").SaveAs _
Filename:="C:\MyDocumets\Excel examples\ReadyTest.CSV",
FileFormat:=xlCSV
Application.DisplayAlerts = True
Windows("PrepareTest.xls").Activate
Range("D1").Select

Calculate

End Sub


Option Explicit

Function LastDataRow(Col As Range) As Long
'Finds last row containing data in column defined by Col
Dim iCol As Integer
iCol = Col.Column
LastDataRow = Col.Columns(1).Cells(65526).End(xlUp).Row
Do While Cells(LastDataRow, iCol) = 0 Or _
Trim(Cells(LastDataRow, iCol)) = "" _
And LastDataRow 1
LastDataRow = LastDataRow - 1
Loop
End Function

If it isn't clear what I am trying to achieve I will elaborate

further.

Thanks
Pat