Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with VBA Code (correct forum?)

Status
Not open for further replies.

pappyb

Technical User
Apr 30, 2009
7
US
Good afternoon everyone. I have some vba code that I use within Excel. I'm trying to modify this code so it will copy/paste values across columns instead of rows. Can someone help me to modify this? I modified it to what I understand but it still is running down rows instead of columns. Thank you very much in advance!

Original code...

Sub pastingvalues()
Set orig = Sheets(1).Range("b1:B20")
For i = 1 To orig.Rows.Count
If IsError(orig.Cells(i, 1)) = False Then
orig.Cells(i, 1) = orig.Cells(i, 1).Value
End If
Next i
End Sub


My modified code (which doesn't work)

Sub pastingvalues()
Set orig = Sheets(1).Range("F3:A06")
For i = 1 To orig.Columns.Count
If IsError(orig.Cells(i, 1)) = False Then
orig.Cells(i, 1) = orig.Cells(i, 1).Value
End If
Next i
End Sub
 


hi,

Please post VBA questions in Forum707.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


Code:
Sub pastingvalues()
dim r as range

For for each r in Sheets(1).Range("b1:B20")
   Sheets(2).Cells(1, r.row) = r.Value
Next i
End Sub
for instance.

However, you never stated where the results should go: sheet, row, columns???

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi,

Could you just use Transpose?

Code:
Sub pastingvalues()

    Range("B1:B20").Select
    Selection.Copy
    ' Select where you want the data to go...
    Range("D1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
End Sub

HTH.

Peter.

Remember- It's nice to be important,
but it's important to be nice :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top