vba code to repeat operation on selected rows

rossy48

New Member
Joined
Aug 8, 2011
Messages
7
Hi,

I am just starting to learn vba and need some help on this.

I have written the code below, to copy the txt in colum h to the same row in column J, and then clear the original cell.


Range("j69") = Range("H69").Value
Range("H69").Select
Selection.ClearContents


what i dont know how do is to repeat the loop (probably something very simple), on the next row, and the row after

and to select the rows that i need to do this. eg rows 50:70, miss out rows 71:75, repeat on rows 76:96, miss rows 97:101 and so on. (may not be so simple)

anybody help???
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
i don't know if i understand you, but try this code

Code:
Sub Test()
Dim LR As Long, c As Range
LR = Range("H" & Rows.Count).End(xlUp).Row
For Each c In Range("H69:H" & LR)
    c.Offset(, 2).Value = c.Value
    c.Value = ""
Next c
End Sub
 
Upvote 0
Yahya it copies all but jumping onto another range...
I made the same as this is but I'm kinda stuck on how to jump on another range..
 
Upvote 0
yes thanks, that worked

I added c.Value = "" & ClearContents to clear the formating of column h, but that didnt work.

how would i do that ?

thanks again, that is very helpful
 
Upvote 0
yes thanks, that worked

I added c.Value = "" & ClearContents to clear the formating of column h, but that didnt work.

how would i do that ?

thanks again, that is very helpful
From Yahya:

instead of c.value="" you write c.clearcontents or c.clear
 
Upvote 0

Forum statistics

Threads
1,224,513
Messages
6,179,214
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top