Excel.Range.Paste Special - Transpose not working

S

shantanu

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,Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone,Type.Missing,true);
}
}
xlsA =
_sheetTemp.get_Range("A1",Type.Missing).EntireColumn;

xlsA.Delete(Excel.XlDeleteShiftDirection.xlShiftToLeft);

_sheet2.SaveAs(@"C:
\PRPTemp1.txt",Excel.XlFileFormat.xlTextWindows,Type.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top