Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Next Blank Row

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Next Blank Row

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Next Blank Row

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Next Blank Row

Is the bottom of the spreadsheet ragged. That is to say each column stops at
a different row number. If so then do you want to go to

1. the first empty cell at the bottom of each column

2. or do you want to go to the first row where no column contains any data?
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Next Blank Row

Try this. It will select the first cell in the first row that is totally
empty:

Sub Macro1()
Dim j As Long
Dim i As Long
Dim r, rr As Range
Set rr = ActiveSheet.UsedRange

j = rr.Rows.Count + rr.Row
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
Cells(i, 1).Select
Exit Sub
End If
Next i
End Sub

--
Gary''s Student


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Next Blank Row

This is another way to get the last row. It is a bit faster as it does not
iterate one cell at a time.

Dim lngLastRow As Long

with sheets("Sheet1")
On Error Resume Next
.select
lngLastRow = .Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On error Goto 0
.cells(lnglastrow + 1, "A").select
end with
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Try this. It will select the first cell in the first row that is totally
empty:

Sub Macro1()
Dim j As Long
Dim i As Long
Dim r, rr As Range
Set rr = ActiveSheet.UsedRange

j = rr.Rows.Count + rr.Row
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
Cells(i, 1).Select
Exit Sub
End If
Next i
End Sub

--
Gary''s Student


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Next Blank Row

Sorry one goof in that code... here is the fix...

Dim lngLastRow As Long

with sheets("Sheet1")
On Error Resume Next
.select
lngLastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On error Goto 0
.cells(lnglastrow + 1, "A").select
end with

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

This is another way to get the last row. It is a bit faster as it does not
iterate one cell at a time.

Dim lngLastRow As Long

with sheets("Sheet1")
On Error Resume Next
.select
lngLastRow = .Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On error Goto 0
.cells(lnglastrow + 1, "A").select
end with
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Try this. It will select the first cell in the first row that is totally
empty:

Sub Macro1()
Dim j As Long
Dim i As Long
Dim r, rr As Range
Set rr = ActiveSheet.UsedRange

j = rr.Rows.Count + rr.Row
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
Cells(i, 1).Select
Exit Sub
End If
Next i
End Sub

--
Gary''s Student


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Next Blank Row

The iteration is there just in case there is an empty row embedded somewhere
in UsedRange. If there are no internal empties, then:

j = rr.Rows.Count + rr.Row

will go one row past UsedRange and insure finding something (I hope)
--
Gary's Student


"Jim Thomlinson" wrote:

This is another way to get the last row. It is a bit faster as it does not
iterate one cell at a time.

Dim lngLastRow As Long

with sheets("Sheet1")
On Error Resume Next
.select
lngLastRow = .Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On error Goto 0
.cells(lnglastrow + 1, "A").select
end with
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Try this. It will select the first cell in the first row that is totally
empty:

Sub Macro1()
Dim j As Long
Dim i As Long
Dim r, rr As Range
Set rr = ActiveSheet.UsedRange

j = rr.Rows.Count + rr.Row
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
Cells(i, 1).Select
Exit Sub
End If
Next i
End Sub

--
Gary''s Student


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Next Blank Row

Thanks Jim. The bottom is ragged adn I'm looking for opt 2 as you have below.

"Jim Thomlinson" wrote:

Is the bottom of the spreadsheet ragged. That is to say each column stops at
a different row number. If so then do you want to go to

1. the first empty cell at the bottom of each column

2. or do you want to go to the first row where no column contains any data?
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Next Blank Row

That will find the first blank row potentially embedded in a list of data.
There may be filled rows below that row, so you need to ensure that you don't
assume that the rows beneath what was found are empty. But fair enough. Yours
will fill in the blank emebedded rows where mine will not. It will find the
very last row that had anything in it. Depends what the OP wants to do.
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

The iteration is there just in case there is an empty row embedded somewhere
in UsedRange. If there are no internal empties, then:

j = rr.Rows.Count + rr.Row

will go one row past UsedRange and insure finding something (I hope)
--
Gary's Student


"Jim Thomlinson" wrote:

This is another way to get the last row. It is a bit faster as it does not
iterate one cell at a time.

Dim lngLastRow As Long

with sheets("Sheet1")
On Error Resume Next
.select
lngLastRow = .Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On error Goto 0
.cells(lnglastrow + 1, "A").select
end with
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Try this. It will select the first cell in the first row that is totally
empty:

Sub Macro1()
Dim j As Long
Dim i As Long
Dim r, rr As Range
Set rr = ActiveSheet.UsedRange

j = rr.Rows.Count + rr.Row
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
Cells(i, 1).Select
Exit Sub
End If
Next i
End Sub

--
Gary''s Student


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Next Blank Row

Gary and I have had a fun time with this one. Assuming that you want to fill
in any blank rows that may exits in your data, go with Gary's. Note you will
need to paste data in one row at a time and run his sub prior to each paste.
If however you just want to find the last row where anything is populated, I
would be more inclined to go with my code. You won't have to worry about
potentialy overwriting any existing data... It's up to you...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

Thanks Jim. The bottom is ragged adn I'm looking for opt 2 as you have below.

"Jim Thomlinson" wrote:

Is the bottom of the spreadsheet ragged. That is to say each column stops at
a different row number. If so then do you want to go to

1. the first empty cell at the bottom of each column

2. or do you want to go to the first row where no column contains any data?
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Next Blank Row

Jim & Gary: You guys are great. I am using Jim's code as it does give me what
I need. Gary, I'm sure I'll be looking for more code sometime soon so you
will have another opportunity to leave your mark with me.

I really don't like asking for help but you two made it very easy and a
great experience.

Have a FANTASTIC weekend!

Sheldon

"Jim Thomlinson" wrote:

That will find the first blank row potentially embedded in a list of data.
There may be filled rows below that row, so you need to ensure that you don't
assume that the rows beneath what was found are empty. But fair enough. Yours
will fill in the blank emebedded rows where mine will not. It will find the
very last row that had anything in it. Depends what the OP wants to do.
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

The iteration is there just in case there is an empty row embedded somewhere
in UsedRange. If there are no internal empties, then:

j = rr.Rows.Count + rr.Row

will go one row past UsedRange and insure finding something (I hope)
--
Gary's Student


"Jim Thomlinson" wrote:

This is another way to get the last row. It is a bit faster as it does not
iterate one cell at a time.

Dim lngLastRow As Long

with sheets("Sheet1")
On Error Resume Next
.select
lngLastRow = .Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On error Goto 0
.cells(lnglastrow + 1, "A").select
end with
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Try this. It will select the first cell in the first row that is totally
empty:

Sub Macro1()
Dim j As Long
Dim i As Long
Dim r, rr As Range
Set rr = ActiveSheet.UsedRange

j = rr.Rows.Count + rr.Row
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
Cells(i, 1).Select
Exit Sub
End If
Next i
End Sub

--
Gary''s Student


"Sheldon" wrote:

That's great help Jim. How can I get this to look at columns A-Q?

"Jim Thomlinson" wrote:

With Sheets("Sheet1")
.select
.cells(rows.count, "A").end(xlup).offset(1,0).select
end with

This will select the first blank row looking at the items in column A...
--
HTH...

Jim Thomlinson


"Sheldon" wrote:

I'm writing a Macro that copies information from several worksheets to one
worksheet and I need the next block of data to be pasted in the first row
that is empty. Can someone help me with some VB code that will select a cell
in the first empty row?

Thanks for any assistance.

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
Excel 2002: Return blank when VLOOKUP on blank cells Mr. Low Excel Discussion (Misc queries) 2 June 4th 09 05:12 PM
Average Formula to display blank cell if named range is blank Rachael F Excel Worksheet Functions 3 February 22nd 08 05:05 PM
Not showing blank and non blank items in filter mode for values Bhaskar Polisetty Excel Worksheet Functions 0 June 20th 06 02:04 PM
Macro code to test for blank row and insert blank row if false Mattie Excel Programming 2 March 29th 06 01:19 AM
Copying and pasting a worksheet to a blank and removing blank rows Bob Reynolds[_3_] Excel Programming 0 June 24th 04 02:55 PM


All times are GMT +1. The time now is 08:57 PM.

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"