Hi,
Here is the code for the macro I created and assigned it a control button,I was getting run time error before as well and unprotected my worksheet.It worked fine but now again I am getting the same error.
Can someone please guide me i M NEW TO VBA.
Thankyou in advance :)
Sub mysecond()
Range("W3").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]>0,RC[-2]=""fully on""),volteq(RC[-1]),IF(AND(RC[-1]>0,RC[-2]=""fully off""),0,IF(AND(RC[-1]<0,RC[-2]=""fully on""),dvolteq(RC[-1]),IF(AND(RC[-1]<0,RC[-2]=""fully off""),0))))"
Range("W1").Select
ActiveCell.FormulaR1C1 = "switch voltage(V)"
Range("X2").Select
Columns("W:W").ColumnWidth = 14.86
Range("W3").Select
Selection.Copy
Range("U3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 2).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SmallScroll ToRight:=3
ActiveWindow.ScrollRow = 20209
ActiveWindow.ScrollRow = 15718
ActiveWindow.ScrollRow = 11227
ActiveWindow.ScrollRow = 6737
ActiveWindow.ScrollRow = 4492
ActiveWindow.ScrollRow = 1
Range("X3").Select
ActiveCell.FormulaR1C1Local = _
"=IF(AND(RC[-3]=""fully on"",OR(AND(RC[-2]>0,RC[-1]>0),AND(RC[-2]<0,RC[-1]<0))),(RC[-2]*RC[-1]*1000),IF(AND(RC[-3]=""fully on"",OR(AND(RC[-2]>0,RC[-1]<0),AND(RC[-2]<0,RC[-1]>0))),(RC[-2]*RC[-1]*-1000),IF(AND(RC[-2]=0,OR(RC[-3]=""fully on"",RC[-3]=""fully off"",RC[-3]=""T on"",RC[-3]=""T off"")),0,IF(AND(RC[-3]=""fully off"",RC[-2]>0),(RC[-2]*RC[-1]*1000),IF(AND(RC[-3" & _
"y off"",RC[-2]<0,RC[-1]<0),(RC[-2]*RC[-1]*1000),IF(AND(RC[-3]=""fully off"",RC[-2]<0,RC[-1]>0),(RC[-2]*RC[-1]*-1000),IF(AND(OR(RC[-3]=""T on"",RC[-3]=""T off""),RC[-2]>0),transeq(RC[-2]),IF(AND(OR(RC[-3]=""T on"",RC[-3]=""T off""),RC[-2]<0),(-1*transeq(RC[-2]))))))))))"
Range("X3").Select
Selection.Copy
Range("U3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 3).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.ScrollRow = 20209
ActiveWindow.ScrollRow = 17963
ActiveWindow.ScrollRow = 15718
ActiveWindow.ScrollRow = 13473
ActiveWindow.ScrollRow = 6737
ActiveWindow.ScrollRow = 2246
ActiveWindow.ScrollRow = 1
Range("X1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "power losses in mJ/s"
Range("X2").Select
Columns("X:X").ColumnWidth = 14.71
Columns("X:X").ColumnWidth = 17.43
Columns("X:X").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("Y1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "energy (mJ)"
Range("Y3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*RC[-10]"
Range("Y3").Select
Selection.Copy
Range("O3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 10).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.ScrollRow = 20209
ActiveWindow.ScrollRow = 13473
ActiveWindow.ScrollRow = 11227
ActiveWindow.ScrollRow = 8982
ActiveWindow.ScrollRow = 4492
ActiveWindow.ScrollRow = 2246
ActiveWindow.ScrollRow = 1
Range("Y1").Select
Columns("Y:Y").ColumnWidth = 11.57
Columns("X:X").ColumnWidth = 21
Range("U8").Select
End Sub