• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro with different ranges

slohman

Member
How can I select different cells instead of just 1 cell


LR = Sheets(SheetName).Range("CC" & Rows.Count).End(xlUp).Row

MyCol = 21

MyRow = 39

For i = 121 To 121

If Sheets(SheetName).Range("CC" & i).Value > 1 Then

Sheets("JJRobbins").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("CC" & i).Value

MyCol = 21

MyRow = MyRow + 1

End If


I am using this macro but now need to select range 121, 124, 127, & 130 so I thin the i = 121 is the problem but dont know to fix it?
 
Hi Slohman,


use the below line,


Code:
For i = 121 To 130 Step 3


instead of For i = 121 To 121


Regards,

Deb
 
BTW.. If 121,124.. are not in a pattern then you can use the below code also...

[pre]
Code:
Sub test()
Source = Array(121, 124, 127, 130)
LR = Sheets(Sheetname).Range("CC" & Rows.Count).End(xlUp).Row
MyCol = 21
MyRow = 39
For i = LBound(Source) To UBound(Source)
If Sheets(Sheetname).Range("CC" & Source(i)) > 1 Then
Sheets("JJRobbins").Cells(MyRow, MyCol) = Sheets(Sheetname).Range("CC" & Source(i))
'MyCol = 21
MyRow = MyRow + 1
End If
Next i
End Sub
[/pre]
Regards,

Deb
 
Back
Top