• 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.

VB Code to copy and paste

Ateeb Ali

Member
Dear Sir,
I need a simple vb code and will link it to the button, when I lick it, the value should be copied from;

Copy T2 into B22 to B31 next empty cell
Copy X2 into C22 to C31 next empty cell
Copy AB2 into D22 to D31 next empty cell
Copy AF2 into E22 to E31 next empty cell
Copy AJ2 into F22 to F31 next empty cell

Example;
"1" When Click the button, Value T2 should be copied to B22, similarly X2 TO C22 and so on
"2" When click same button again, the value of cell T2 should be copied in B23 since B22 is no mire a empty cell
if I clear value in Cell B22, it should work in same way "1"
 
Hi Ateeb,
as you have not given a sheet name, I have used activesheet, which will require your button to be on the same sheet as the rest of your referenced cells.
Try this:
Code:
Sub chandooAteeb()
Dim rowcounter As Integer
Dim arraycounter As Integer
Dim inputcells(4, 1) As String
inputcells(0, 0) = "T2"
inputcells(0, 1) = "B"
inputcells(1, 0) = "X2"
inputcells(1, 1) = "C"
inputcells(2, 0) = "AB2"
inputcells(2, 1) = "D"
inputcells(3, 0) = "AF2"
inputcells(3, 1) = "E"
inputcells(4, 0) = "AJ2"
inputcells(4, 1) = "F"
For arraycounter = 0 To 4
    For rowcounter = 22 To 31
        If ActiveSheet.Range(inputcells(arraycounter, 1) & rowcounter) = "" Then
            ActiveSheet.Range(inputcells(arraycounter, 1) & rowcounter) = ActiveSheet.Range(inputcells(arraycounter, 0)).Value
            Exit For
        End If
    Next
Next
End Sub

If this was helpful, please click 'Like' on the bottom right!

Stevie
 
Back
Top