Copy from Random cells paste in random cells

dinesh shah

New Member
Joined
Aug 16, 2012
Messages
24
Dear friends,

I want to copy values from random cells in one sheet and paste those values in random cells of another sheet.

Please suggest vba code for the same.

Thanks in advance for the help
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
VBA Code:
Sub test22222222()
Sheets("sheet1").Cells(Int(Rnd() * 10) + 1, Int(Rnd() * 10) + 1).Copy Sheets("sheet2").Cells(Int(Rnd() * 10) + 1, Int(Rnd() * 10) + 1)
End Sub
 
Upvote 0
VBA Code:
Sub test22222222()
Sheets("sheet1").Cells(Int(Rnd() * 10) + 1, Int(Rnd() * 10) + 1).Copy Sheets("sheet2").Cells(Int(Rnd() * 10) + 1, Int(Rnd() * 10) + 1)
End Sub
VBA Code:
Sub test22222222()
Sheets("sheet1").Cells(Int(Rnd() * 10) + 1, Int(Rnd() * 10) + 1).Copy Sheets("sheet2").Cells(Int(Rnd() * 10) + 1, Int(Rnd() * 10) + 1)
End Sub
Thanks Mr.Mohadin. I will try it very soon. In the meantime can you please elaborate the code for my more better understanding?
 
Upvote 0
For each column & row use random number Rnd()
then add 1 to avoid row or column beeing (0) int to get the integer of it
Rich (BB code):
Sheets("sheet1").Cells(row,column).copy And paste in  sheets("sheet2").Cells(row,column)
Hope this helps
 
Upvote 0
VBA Code:
Sub test()
    Dim DIS As Worksheet
    Set DIS = Sheets("Sheet2")
    With Sheets("sheet1")
        .Range("A1").Copy DIS.Range("B1")
        .Range("B1").Copy DIS.Range("E1")
        .Range("D1").Copy DIS.Range("F1")
        .Range("F1").Copy DIS.Range("H1")
    End With
End Sub
Or
VBA Code:
Sub test2()
    Dim DIS As Worksheet
    Set DIS = Sheets("Sheet2")
    With Sheets("sheet1").Range("A1")
        .Copy DIS.Range("B1")
        .Offset(, 1).Copy DIS.Range("E1")
        .Offset(, 3).Copy DIS.Range("F1")
        .Offset(, 5).Copy DIS.Range("H1")
    End With
End Sub
 
Upvote 0
Solution
You're Very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,214,413
Messages
6,119,372
Members
448,888
Latest member
Arle8907

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