By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,208 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,208 IT Pros & Developers. It's quick & easy.

Excel.Range.Paste Special - Transpose not working

P: n/a
I am trying to convert a macro code to c# that will copy the values of
a column and paste to anather through paste special. Everything is
working fine but the transpose meathod to paste the column value as
row value is not working. Can someone kindly look into the code, if i
am missing something.

C# Code
------------
private void ManipulateXLS()
{
try
{
Excel.Range xlsManip,xlsA,xlsB,xlsC;
_book2 = OpenExcelWorkbook(@"C:\PRPTemp.xls");
_sheet2 = (Excel.Worksheet)_book2.ActiveSheet;
_sheet2.Select(Type.Missing);
Excel.Worksheet _sheetTemp =
(Excel.Worksheet)_book2.Worksheets[1];
xlsManip = _sheetTemp.UsedRange;
for (int i = 1; i <= xlsManip.Rows.Count; i++)
{
xlsA = _sheetTemp.get_Range("A" + i.ToString(),
Type.Missing);
xlsC = _sheetTemp.get_Range("C" +
i.ToString(),Type.Missing);
if(xlsA.Value!=null)
{
xlsA.Copy(Type.Missing);

xlsC.PasteSpecial(Excel.XlPasteType.xlPasteAll,Exc el.XlPasteSpecialOperation.xlPasteSpecialOperation None,Type.Missing,true);
}
}
xlsA =
_sheetTemp.get_Range("A1",Type.Missing).EntireColu mn;

xlsA.Delete(Excel.XlDeleteShiftDirection.xlShiftTo Left);

_sheet2.SaveAs(@"C:
\PRPTemp1.txt",Excel.XlFileFormat.xlTextWindows,Ty pe.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing);
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
Macro code
---------------
Sub Test()
'
' Test Macro
' Macro recorded 6/15/2007 by shsen
'

'
Range("A1").Select
ActiveWindow.SmallScroll Down:=69
Range("A1:A88").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-93
Range("C1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone,
SkipBlanks:=False _
, Transpose:=True
Range("B1").Select
ActiveWindow.SmallScroll Down:=66
Range("B1:B88").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-96
Range("C2").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone,
SkipBlanks:=False _
, Transpose:=True
Columns("A:B").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("C2").Select
End Sub

Jun 18 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.