Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help to correct code
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help to correct code
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help to correct code
O dear, I think I have eaten too much turkey, please ignore the last post
the original is correct after all. "Pat" wrote in message ... 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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help to correct code
You still didn't explain what went wrong, but when I tried it I got stuck
here 'Find start of data based on reference in Sheet1 A1 FirstRow = Range(.[A1].Formula).Row I don't understand your comment. The syntax is wrong, but I don't know what to put as I don't know what row value are you trying to get here? -- HTH RP (remove nothere from the email address if mailing direct) "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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help to correct code
I got stuck at the same location also, the comment refers to PrepareTest.xls
but as the syntax is wrong please ignore where approbate. I am trying to get the data from Master.xls into A1 "Bob Phillips" wrote in message ... You still didn't explain what went wrong, but when I tried it I got stuck here 'Find start of data based on reference in Sheet1 A1 FirstRow = Range(.[A1].Formula).Row I don't understand your comment. The syntax is wrong, but I don't know what to put as I don't know what row value are you trying to get here? -- HTH RP (remove nothere from the email address if mailing direct) "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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to search for a code, and have the correct information auto fi | Excel Discussion (Misc queries) | |||
#Value! error on code that should be correct? | Excel Discussion (Misc queries) | |||
Can you help with the correct translation of this code? | Excel Programming | |||
I will never, ever get this correct ... | Excel Programming | |||
I will never, ever get this correct ... | Excel Programming |