Click here to Skip to main content
14,698,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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()
'
' mysecond Macro
'
' Keyboard Shortcut: Ctrl+Shift+L
'
    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
Posted
Updated 29-Jul-15 14:52pm
v2

1 solution

Advice: run you program with the debugger, abuse the debugger.

First of all find where the problem is.
Advice: Try to make a shorter program that exhibit the error, it help helpers to figure out what goes wrong.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900