Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Get data reference to last row

Hello,

I've had a great deal of success with assistance from several experts on
this site. I thank those experts who provide their much needed assistance to
those like me, somewhat familiar with vba be still in need of much
improvement. I am currently using a reference to A1:K500 in this bit of
fabulous code I've picked up form this site (I believe from Mr. De Bruin) but
what I really what is through the end of the used range or to the last row.
the code is as follows:

Sub GetLastReportsData()
Dim MyPath As String
Dim FilesInPath As String
Dim sh As Worksheet
Dim MyFiles() As String
Dim FNum As Long
Dim rnum As Long
Dim destrange As Range

MyPath = Location & "\Prior Report\" ' <<<< Change

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls*")
If FilesInPath = "" Then
MsgBox "No files found in Prior Report's Folder"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = "Olddata"
Columns("E:G").Select
Selection.NumberFormat = "[$-409]dd-mmm-yy"

' 'Fill the array(myFiles)with the list of Excel files in the folder
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)

'Find the last row with data
rnum = lastrow(sh)

'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")

' Copy the workbook name in Column E
'sh.Cells(rnum + 1, "E").Value = MyPath & MyFiles(Fnum)

'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
'Change the Sheet name and range as you like
GetData MyPath & MyFiles(FNum), "EventWS", "A1:K500", destrange,
False, False
Next
End If

'Columns("C:C").Delete

namefixer

Range("D:F,I:I").Select

Selection.NumberFormat = "[$-409]d-mmm-yy;@"
Range("D2").Select

CleanUp:
Application.ScreenUpdating = True

End Sub


Thanks once again in advance for your assistance.
--
By persisting in your path, though you forfeit the little, you gain the
great.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Get data reference to last row

You may be able to use something like this

myWS.usedrange.address in place of A1:K500. I'm not sure what the
worksheet name is you're working with, but you should be able to figure that
out.

"DavidH56" wrote:

Hello,

I've had a great deal of success with assistance from several experts on
this site. I thank those experts who provide their much needed assistance to
those like me, somewhat familiar with vba be still in need of much
improvement. I am currently using a reference to A1:K500 in this bit of
fabulous code I've picked up form this site (I believe from Mr. De Bruin) but
what I really what is through the end of the used range or to the last row.
the code is as follows:

Sub GetLastReportsData()
Dim MyPath As String
Dim FilesInPath As String
Dim sh As Worksheet
Dim MyFiles() As String
Dim FNum As Long
Dim rnum As Long
Dim destrange As Range

MyPath = Location & "\Prior Report\" ' <<<< Change

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls*")
If FilesInPath = "" Then
MsgBox "No files found in Prior Report's Folder"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = "Olddata"
Columns("E:G").Select
Selection.NumberFormat = "[$-409]dd-mmm-yy"

' 'Fill the array(myFiles)with the list of Excel files in the folder
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)

'Find the last row with data
rnum = lastrow(sh)

'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")

' Copy the workbook name in Column E
'sh.Cells(rnum + 1, "E").Value = MyPath & MyFiles(Fnum)

'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
'Change the Sheet name and range as you like
GetData MyPath & MyFiles(FNum), "EventWS", "A1:K500", destrange,
False, False
Next
End If

'Columns("C:C").Delete

namefixer

Range("D:F,I:I").Select

Selection.NumberFormat = "[$-409]d-mmm-yy;@"
Range("D2").Select

CleanUp:
Application.ScreenUpdating = True

End Sub


Thanks once again in advance for your assistance.
--
By persisting in your path, though you forfeit the little, you gain the
great.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Get data reference to last row

There is a example for this on the site
http://www.rondebruin.nl/copy3.htm

Read the information above the first macro


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"DavidH56" wrote in message ...
Hello,

I've had a great deal of success with assistance from several experts on
this site. I thank those experts who provide their much needed assistance to
those like me, somewhat familiar with vba be still in need of much
improvement. I am currently using a reference to A1:K500 in this bit of
fabulous code I've picked up form this site (I believe from Mr. De Bruin) but
what I really what is through the end of the used range or to the last row.
the code is as follows:

Sub GetLastReportsData()
Dim MyPath As String
Dim FilesInPath As String
Dim sh As Worksheet
Dim MyFiles() As String
Dim FNum As Long
Dim rnum As Long
Dim destrange As Range

MyPath = Location & "\Prior Report\" ' <<<< Change

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls*")
If FilesInPath = "" Then
MsgBox "No files found in Prior Report's Folder"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = "Olddata"
Columns("E:G").Select
Selection.NumberFormat = "[$-409]dd-mmm-yy"

' 'Fill the array(myFiles)with the list of Excel files in the folder
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)

'Find the last row with data
rnum = lastrow(sh)

'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")

' Copy the workbook name in Column E
'sh.Cells(rnum + 1, "E").Value = MyPath & MyFiles(Fnum)

'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
'Change the Sheet name and range as you like
GetData MyPath & MyFiles(FNum), "EventWS", "A1:K500", destrange,
False, False
Next
End If

'Columns("C:C").Delete

namefixer

Range("D:F,I:I").Select

Selection.NumberFormat = "[$-409]d-mmm-yy;@"
Range("D2").Select

CleanUp:
Application.ScreenUpdating = True

End Sub


Thanks once again in advance for your assistance.
--
By persisting in your path, though you forfeit the little, you gain the
great.


__________ Information from ESET Smart Security, version of virus signature database 3961 (20090325) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 3961 (20090325) __________

The message was checked by ESET Smart Security.

http://www.eset.com



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Get data reference to last row

Thanks for the quick response Barb. I tried your code but it did not work.
I'm missing values from formulas in coulmn K.

Thanks
--
By persisting in your path, though you forfeit the little, you gain the
great.



"Barb Reinhardt" wrote:

You may be able to use something like this

myWS.usedrange.address in place of A1:K500. I'm not sure what the
worksheet name is you're working with, but you should be able to figure that
out.

"DavidH56" wrote:

Hello,

I've had a great deal of success with assistance from several experts on
this site. I thank those experts who provide their much needed assistance to
those like me, somewhat familiar with vba be still in need of much
improvement. I am currently using a reference to A1:K500 in this bit of
fabulous code I've picked up form this site (I believe from Mr. De Bruin) but
what I really what is through the end of the used range or to the last row.
the code is as follows:

Sub GetLastReportsData()
Dim MyPath As String
Dim FilesInPath As String
Dim sh As Worksheet
Dim MyFiles() As String
Dim FNum As Long
Dim rnum As Long
Dim destrange As Range

MyPath = Location & "\Prior Report\" ' <<<< Change

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls*")
If FilesInPath = "" Then
MsgBox "No files found in Prior Report's Folder"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = "Olddata"
Columns("E:G").Select
Selection.NumberFormat = "[$-409]dd-mmm-yy"

' 'Fill the array(myFiles)with the list of Excel files in the folder
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)

'Find the last row with data
rnum = lastrow(sh)

'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")

' Copy the workbook name in Column E
'sh.Cells(rnum + 1, "E").Value = MyPath & MyFiles(Fnum)

'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
'Change the Sheet name and range as you like
GetData MyPath & MyFiles(FNum), "EventWS", "A1:K500", destrange,
False, False
Next
End If

'Columns("C:C").Delete

namefixer

Range("D:F,I:I").Select

Selection.NumberFormat = "[$-409]d-mmm-yy;@"
Range("D2").Select

CleanUp:
Application.ScreenUpdating = True

End Sub


Thanks once again in advance for your assistance.
--
By persisting in your path, though you forfeit the little, you gain the
great.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Get data reference to last row

Check out also the Merge add-in
http://www.rondebruin.nl/merge.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"DavidH56" wrote in message ...
Hello,

I've had a great deal of success with assistance from several experts on
this site. I thank those experts who provide their much needed assistance to
those like me, somewhat familiar with vba be still in need of much
improvement. I am currently using a reference to A1:K500 in this bit of
fabulous code I've picked up form this site (I believe from Mr. De Bruin) but
what I really what is through the end of the used range or to the last row.
the code is as follows:

Sub GetLastReportsData()
Dim MyPath As String
Dim FilesInPath As String
Dim sh As Worksheet
Dim MyFiles() As String
Dim FNum As Long
Dim rnum As Long
Dim destrange As Range

MyPath = Location & "\Prior Report\" ' <<<< Change

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls*")
If FilesInPath = "" Then
MsgBox "No files found in Prior Report's Folder"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = "Olddata"
Columns("E:G").Select
Selection.NumberFormat = "[$-409]dd-mmm-yy"

' 'Fill the array(myFiles)with the list of Excel files in the folder
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)

'Find the last row with data
rnum = lastrow(sh)

'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")

' Copy the workbook name in Column E
'sh.Cells(rnum + 1, "E").Value = MyPath & MyFiles(Fnum)

'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
'Change the Sheet name and range as you like
GetData MyPath & MyFiles(FNum), "EventWS", "A1:K500", destrange,
False, False
Next
End If

'Columns("C:C").Delete

namefixer

Range("D:F,I:I").Select

Selection.NumberFormat = "[$-409]d-mmm-yy;@"
Range("D2").Select

CleanUp:
Application.ScreenUpdating = True

End Sub


Thanks once again in advance for your assistance.
--
By persisting in your path, though you forfeit the little, you gain the
great.


__________ Information from ESET Smart Security, version of virus signature database 3961 (20090325) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 3961 (20090325) __________

The message was checked by ESET Smart Security.

http://www.eset.com





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Get data reference to last row

Thanks Ron this is a lot of good info. It worked out just great when i
reference cells A:K.
--
By persisting in your path, though you forfeit the little, you gain the
great.



"Ron de Bruin" wrote:

Check out also the Merge add-in
http://www.rondebruin.nl/merge.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"DavidH56" wrote in message ...
Hello,

I've had a great deal of success with assistance from several experts on
this site. I thank those experts who provide their much needed assistance to
those like me, somewhat familiar with vba be still in need of much
improvement. I am currently using a reference to A1:K500 in this bit of
fabulous code I've picked up form this site (I believe from Mr. De Bruin) but
what I really what is through the end of the used range or to the last row.
the code is as follows:

Sub GetLastReportsData()
Dim MyPath As String
Dim FilesInPath As String
Dim sh As Worksheet
Dim MyFiles() As String
Dim FNum As Long
Dim rnum As Long
Dim destrange As Range

MyPath = Location & "\Prior Report\" ' <<<< Change

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls*")
If FilesInPath = "" Then
MsgBox "No files found in Prior Report's Folder"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False

'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = "Olddata"
Columns("E:G").Select
Selection.NumberFormat = "[$-409]dd-mmm-yy"

' 'Fill the array(myFiles)with the list of Excel files in the folder
FNum = 0
Do While FilesInPath < ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If FNum 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)

'Find the last row with data
rnum = lastrow(sh)

'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")

' Copy the workbook name in Column E
'sh.Cells(rnum + 1, "E").Value = MyPath & MyFiles(Fnum)

'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
'Change the Sheet name and range as you like
GetData MyPath & MyFiles(FNum), "EventWS", "A1:K500", destrange,
False, False
Next
End If

'Columns("C:C").Delete

namefixer

Range("D:F,I:I").Select

Selection.NumberFormat = "[$-409]d-mmm-yy;@"
Range("D2").Select

CleanUp:
Application.ScreenUpdating = True

End Sub


Thanks once again in advance for your assistance.
--
By persisting in your path, though you forfeit the little, you gain the
great.


__________ Information from ESET Smart Security, version of virus signature database 3961 (20090325) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 3961 (20090325) __________

The message was checked by ESET Smart Security.

http://www.eset.com




Reply
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
Reference Data in 2 Worksheets [email protected] Excel Discussion (Misc queries) 0 June 5th 09 12:35 AM
How to reference to a column of data? Jay Excel Discussion (Misc queries) 4 March 10th 09 08:54 PM
DATA REFERENCE Yuanhang Excel Discussion (Misc queries) 1 February 15th 08 11:45 PM
Data Reference Challenge FishHead Excel Discussion (Misc queries) 0 April 26th 06 06:16 PM
Reference the last 13 rows of data Robert Gillard Excel Programming 4 May 28th 05 06:26 PM


All times are GMT +1. The time now is 09:27 AM.

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

About Us

"It's about Microsoft Excel"