LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Help to correct code

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search for a code, and have the correct information auto fi Jared Excel Discussion (Misc queries) 4 November 9th 09 05:04 AM
#Value! error on code that should be correct? RHein Excel Discussion (Misc queries) 2 January 3rd 08 03:19 AM
Can you help with the correct translation of this code? Just For Fun... Excel Programming 0 September 30th 04 06:16 AM
I will never, ever get this correct ... Dan E[_2_] Excel Programming 0 September 2nd 03 03:41 PM
I will never, ever get this correct ... Chip Pearson Excel Programming 0 September 2nd 03 03:34 PM


All times are GMT +1. The time now is 11:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"