Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default copy, find next blank row, paste special location

Here is what I want to do, have a macro to
Sheet 1 copy b17:017
I have this done so far as
Worksheets("Sheet 1").Range("B17:O17").Copy
That works

Now how do I find the next blank row on Sheet 2
The range is between rows A12:A36
But I want to paste the values copied to the blank row to cells F??:S??
where ?? would be the found blank row number.
And if now blank rows between A12:A36 report an error and stop
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default copy, find next blank row, paste special location

If there's nothing under rows 12:36 and you can pick out a column that always
has data in it, you can use that to get the next blank row.

I'm gonna use column A:

Sub testme1()

Dim NextRow As Long

With Worksheets("sheet 2")
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With

If NextRow < 12 Then
NextRow = 12
ElseIf NextRow 36 Then
MsgBox "no Blank rows!"
Exit Sub
End If

Worksheets("sheet 1").Range("b17:o17").Copy _
Destination:=Worksheets("sheet 2").Cells(NextRow, "F")

End Sub

If your data isn't laid out to allow you to do something like that, you can loop
through those rows.


Option Explicit
Sub testme2()

Dim NextRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

With Worksheets("sheet 2")
FirstRow = 12
LastRow = 36
NextRow = -1
For iRow = FirstRow To LastRow
If Application.CountA(.Rows(iRow)) = 0 Then
NextRow = iRow
Exit For
End If
Next iRow

If NextRow = -1 Then
MsgBox "no more rows"
End If
End With

Worksheets("sheet 1").Range("b17:o17").Copy _
Destination:=Worksheets("sheet 2").Cells(NextRow, "F")

End Sub




Pete wrote:

Here is what I want to do, have a macro to
Sheet 1 copy b17:017
I have this done so far as
Worksheets("Sheet 1").Range("B17:O17").Copy
That works

Now how do I find the next blank row on Sheet 2
The range is between rows A12:A36
But I want to paste the values copied to the blank row to cells F??:S??
where ?? would be the found blank row number.
And if now blank rows between A12:A36 report an error and stop


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default copy, find next blank row, paste special location

Try this

Sub FindBlankRow()
Dim R As Integer, C As Integer
R = 12
C = 1
With Workbooks(1)
With Worksheets(1)
.Range("B17:O17").Copy
Do While .Cells(R, C) < ""
.Cells(R, C).Activate
R = R + 1
If Cells(R, C) = "" Then
C = 6
.Cells(R, C).PasteSpecial Paste:=xlValues
Exit Do
End If
If R = 36 Then
MsgBox ("No blank rows")
Exit Do
End If
Loop
End With
End With
End Sub

Let me know if it works for you.

--
Bob Calvanese
"Pete" wrote in message
...
Here is what I want to do, have a macro to
Sheet 1 copy b17:017
I have this done so far as
Worksheets("Sheet 1").Range("B17:O17").Copy
That works

Now how do I find the next blank row on Sheet 2
The range is between rows A12:A36
But I want to paste the values copied to the blank row to cells F??:S??
where ?? would be the found blank row number.
And if now blank rows between A12:A36 report an error and stop



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default copy, find next blank row, paste special location

You can take this line of code out...

..Cells(R, C).Activate

I only put it in to test.

--
Bob Calvanese
"Bob Calvanese" wrote in message
...
Try this

Sub FindBlankRow()
Dim R As Integer, C As Integer
R = 12
C = 1
With Workbooks(1)
With Worksheets(1)
.Range("B17:O17").Copy
Do While .Cells(R, C) < ""
.Cells(R, C).Activate
R = R + 1
If Cells(R, C) = "" Then
C = 6
.Cells(R, C).PasteSpecial Paste:=xlValues
Exit Do
End If
If R = 36 Then
MsgBox ("No blank rows")
Exit Do
End If
Loop
End With
End With
End Sub

Let me know if it works for you.

--
Bob Calvanese
"Pete" wrote in message
...
Here is what I want to do, have a macro to
Sheet 1 copy b17:017
I have this done so far as
Worksheets("Sheet 1").Range("B17:O17").Copy
That works

Now how do I find the next blank row on Sheet 2
The range is between rows A12:A36
But I want to paste the values copied to the blank row to cells F??:S??
where ?? would be the found blank row number.
And if now blank rows between A12:A36 report an error and stop





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
Can't Copy and Paste or Paste Special between Excel Workbooks wllee Excel Discussion (Misc queries) 5 April 29th 23 03:43 AM
Macro - Copy/Paste Special to Next Blank Line lajohn63 New Users to Excel 2 August 27th 12 09:27 PM
Copy; Paste; Paste Special are disabled Mack Neff[_3_] Excel Discussion (Misc queries) 0 April 28th 08 06:29 PM
Zero replaces blank field when paste special is used Baseball Greg Excel Worksheet Functions 5 November 29th 05 04:45 AM
Dynamic Copy/Paste Special Formulas/Paste Special Values Sharon Perez Excel Programming 3 August 7th 04 09:49 PM


All times are GMT +1. The time now is 11:29 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"