Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA problem

Status
Not open for further replies.

Sadukar

Technical User
Feb 19, 2003
159
IE
I am copying a a range of cells and pasting them depending on a value in a range. For example If a cell contained a "R" then My code would move up one cell and one to the right and copy as far as the end of range. (be5)
It would then paste to cells to the right of where "R" value is.

I can do this by using:
For Each Cell In Range("f5:be5")
If Cell.Value = "R" Then
Range(Cell.Offset(-1, 1), Cells(4, "BE")).Copy Destination:=Cell.Offset(0, 1)
End If
Next

My problem is that there may be more than one "R" in the range I am checking. Using the above code it only finds the first "R" and then pastes over the rest. I want it to choice the last "R" and then Copy and Paste from there onwards. This is what I've tried for this problem.

Dim str As String
For Each Cell In Range("f5:be5")
If Cell.Value = "R" Then
str = Cell.AddressLocal
Range(str.Value.Offset(-1, 1), Cells(4, "BE")).Copy
_ Destination:=str.Value.Offset(0, 1)
End If
Next

My problem here is Where and How to use the str. It doesn't work as is.
Any sugestions??

Thanks for reading
S.
 
from my limited knowledge of excel vba you have assigned str as a cell address in string format surely you need to refer to it like range(str).value.Offset(-1, 1), Cells(4, "BE").Copy

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top