copying values from range

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
Hi All,

I have been working on the following code which selects all the values in column A (rng1).

I then have it go to the last cell of the data in column D and select the next blank available row.

What I am stuck on as I want each value from the rng1 to be put in the next cell to the right in column D, so the first A1 value would go into the first available blank cell in column D, A2 value would go into E, A3 would go into F etc...

At the moment the script is just putting the last value of column A into the blank cell in column D.

Code:
Sub test1()
Dim rng1 As Range
 
Range("A" & Rows.Count).End(xlUp).Select
Set rng1 = Selection
Range("D" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
 
With rng1
Dim cell As Range
For Each cell In Selection.Cells
If cell.HasFormula = False Then
End If
ActiveCell.Value = rng1.Value
 
ActiveCell.Offset(0, 1).Select
Next
End With
 
 
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
try giving the offset a variable for instance

j = 1

ActiveCell.Value = rng1.Value

ActiveCell.Offset(0, j).Select
j = j + 1
 
Upvote 0
Hi Dryver,

unfortunately it still does the same thing.

Code:
Sub test1()
Dim rng1 As Range
Range("A" & Rows.Count).End(xlUp).Select
Set rng1 = Selection
Range("D" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
 
With rng1
Dim cell As Range
For Each cell In Selection.Cells
If cell.HasFormula = False Then
End If
j = 1
ActiveCell.Value = rng1.Value
ActiveCell.Offset(0, j).Select
j = j + 1
Next
End With
 
End Sub
 
Upvote 0
yes I suppose it would as you have already given the cell a value try somrthing like

ActiveCell.Offset(0, j).value = rng1.value

and delete the line above
 
Upvote 0
Code:
Sub test1()
 
Range("A1", Range("A" & Rows.Count).End(xlUp)).Copy
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, True
Application.CutCopyMode = True

End Sub
 
Upvote 0
Thanks Alphafrog, once again you have come through, you make it all look so easy.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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