Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Offset issue?

I am looking to paste a row of data onto a cell if the cell meets the
criteria. What I cannot seem to get this macro to do is move down to
the next cell, evaluate the contents, if it matches the criteria, paste
the copied row of data, then move onto the next cell until it
encounters a blank cell. Any ideas?

Range("$AP$2:$DZ$2").Select
Selection.Copy

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until IsEmpty(rg1)
If rg1 = "2" Then
ActiveSheet.Paste
Else
Set rg1 = rg1.Offset(1, 0)

End If
Loop
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Offset issue?

Sub copyData()
Dim rg1 As Range, cell As Range
Dim rg2 As Range
Set rg2 = Range("$AP$2:$DZ$2")
Set rg1 = Range("AP12", Cells(Rows.Count, "AP").End(xlUp))
For Each cell In rg1
If cell.Value = 2 Then
rg2.Copy cell
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"BigWave@AC" wrote:

I am looking to paste a row of data onto a cell if the cell meets the
criteria. What I cannot seem to get this macro to do is move down to
the next cell, evaluate the contents, if it matches the criteria, paste
the copied row of data, then move onto the next cell until it
encounters a blank cell. Any ideas?

Range("$AP$2:$DZ$2").Select
Selection.Copy

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until IsEmpty(rg1)
If rg1 = "2" Then
ActiveSheet.Paste
Else
Set rg1 = rg1.Offset(1, 0)

End If
Loop
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Offset issue?

You have all of the pieces but you need to re-arrange them a bit... Try this...

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until rg1.Value = ""
If rg1 = "2" Then Range("$AP$2:$DZ$2").Copy Destination:=rng1
Set rg1 = rg1.Offset(1, 0)
Loop
End Sub


--
HTH...

Jim Thomlinson


"BigWave@AC" wrote:

I am looking to paste a row of data onto a cell if the cell meets the
criteria. What I cannot seem to get this macro to do is move down to
the next cell, evaluate the contents, if it matches the criteria, paste
the copied row of data, then move onto the next cell until it
encounters a blank cell. Any ideas?

Range("$AP$2:$DZ$2").Select
Selection.Copy

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until IsEmpty(rg1)
If rg1 = "2" Then
ActiveSheet.Paste
Else
Set rg1 = rg1.Offset(1, 0)

End If
Loop
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Offset issue?

Thank you for the tip. works perfectly.


Jim Thomlinson wrote:
You have all of the pieces but you need to re-arrange them a bit... Try this...

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until rg1.Value = ""
If rg1 = "2" Then Range("$AP$2:$DZ$2").Copy Destination:=rng1
Set rg1 = rg1.Offset(1, 0)
Loop
End Sub


--
HTH...

Jim Thomlinson


"BigWave@AC" wrote:

I am looking to paste a row of data onto a cell if the cell meets the
criteria. What I cannot seem to get this macro to do is move down to
the next cell, evaluate the contents, if it matches the criteria, paste
the copied row of data, then move onto the next cell until it
encounters a blank cell. Any ideas?

Range("$AP$2:$DZ$2").Select
Selection.Copy

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until IsEmpty(rg1)
If rg1 = "2" Then
ActiveSheet.Paste
Else
Set rg1 = rg1.Offset(1, 0)

End If
Loop
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Offset issue?

Thank you for the tip. works perfectly.


Jim Thomlinson wrote:
You have all of the pieces but you need to re-arrange them a bit... Try this...

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until rg1.Value = ""
If rg1 = "2" Then Range("$AP$2:$DZ$2").Copy Destination:=rng1
Set rg1 = rg1.Offset(1, 0)
Loop
End Sub


--
HTH...

Jim Thomlinson


"BigWave@AC" wrote:

I am looking to paste a row of data onto a cell if the cell meets the
criteria. What I cannot seem to get this macro to do is move down to
the next cell, evaluate the contents, if it matches the criteria, paste
the copied row of data, then move onto the next cell until it
encounters a blank cell. Any ideas?

Range("$AP$2:$DZ$2").Select
Selection.Copy

Dim rg1 As Range
Set rg1 = Range("AP12")

Do Until IsEmpty(rg1)
If rg1 = "2" Then
ActiveSheet.Paste
Else
Set rg1 = rg1.Offset(1, 0)

End If
Loop
End Sub



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
Cell offset issue MGarrison Excel Worksheet Functions 3 July 31st 08 03:52 PM
Compare Cell Values, Offset(-1,0), Offset(-1,-1), and xlFillDefaul RyGuy Excel Worksheet Functions 2 September 28th 07 10:54 PM
Offset Jeze77 Excel Discussion (Misc queries) 0 August 31st 07 02:14 PM
offset? ward376 Excel Programming 5 June 7th 06 01:32 AM
Problem with Range.Cells.Offset and Range.Cells( row + offset, column) [email protected] Excel Programming 2 August 22nd 05 05:25 AM


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