Anyone can take a look of my code?

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
Sub copy_and_paste()
Dim rg As Range, rg1 As Range, rg2 As Range, rg3 As Range
n = Range("a65535").End(xlUp).Row
For i = 1 To n
Set rg = Union(Range("B" & i & ":C" & i), Range("U" & i & ":V" & i))
If Range("A" & i).Interior.ColorIndex = 3 And Range("A" & i).Interior.ColorIndex = 36 Then
If rg1 Is noting Then Set rg1 = rg Else Set rg = Union(rg1, rg)
End If
If Range("A" & i).Interior.ColorIndex = 43 And Range("U" & i).Value <> 0 Then
If rg2 Is noting Then Set rg2 = rg Else Set rg = Union(rg2, rg)
End If
If Range("U" & i).Value = 0 Then
If rg3 Is noting Then Set rg3 = rg Else Set rg = Union(rg3, rg)
End If
Next
rg1.Copy Sheets(Sheet2).Range("A8")
rg2.Copy Sheets(Sheet2).Range("I8")
rg3.Copy Sheets(Sheet2).Range("Q8")
End Sub

I think is because this (If Range("U" & i).Value = 0), but I dun know how to edit the codes
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I think is because this (If Range("U" & i).Value = 0), but I dun know how to edit the codes
You think what is because of this? Are you getting an error? If so, what is the error number and error description? You might also help us out by telling us what the code is supposed to be doing.
 
Upvote 0
You think what is because of this? Are you getting an error? If so, what is the error number and error description? You might also help us out by telling us what the code is supposed to be doing.

This code got error, error 424, it shows that the error is occur in "If rg3 Is nothing Then"
I think is due to I set the condition that "Range("U"& i ).Value = 0"
And one more thing I wanna to ask is that the color code I set in Column A is from the conditional formatting, is the code will still be working??
 
Upvote 0
This code got error, error 424, it shows that the error is occur in "If rg3 Is nothing Then"
I think is due to I set the condition that "Range("U"& i ).Value = 0"
What exactly is your code supposed to be doing?


And one more thing I wanna to ask is that the color code I set in Column A is from the conditional formatting, is the code will still be working??
It depends... what version of Excel will be used to run your code?
 
Upvote 0
What exactly is your code supposed to be doing?

The code is supposed to copy and paste the selected cells based on condition

It depends... what version of Excel will be used to run your code?

excel 2003, Actually I am very new of VBA, this is I search online and copy and do some edit
 
Upvote 0
excel 2003, Actually I am very new of VBA, this is I search online and copy and do some edit
Excel 2003 cannot see cell colors produced by Conditional Formatting. You will have to use the same formula you used in the Conditional Formatting for the cell(s) and test that for True/False... if True then you know the Conditional Formatting colored the cells. If you tell us the cell address and the formula used in Conditional Formatting for it, we will see if we can get you the correct code to use.
 
Upvote 0
Excel 2003 cannot see cell colors produced by Conditional Formatting. You will have to use the same formula you used in the Conditional Formatting for the cell(s) and test that for True/False... if True then you know the Conditional Formatting colored the cells. If you tell us the cell address and the formula used in Conditional Formatting for it, we will see if we can get you the correct code to use.

Oh, no wonder the color index show -4142
But how can I solve the error 424 for
If rg3 Is nothing then
Because I think due to 0 is same is nothing, so error 424 appear
And
My formula is :
Formula=$U8>10------ colored as red
Formula=AND($U8>=5, $U8<10)------ colored as light yellow
=AND($U8>=0, $U8<5) -------colored as green
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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