Why am I getting this error on this simple code?

dan7055

Active Member
Joined
Jul 9, 2015
Messages
312
I get an error on the line: "Columns("4:4").insert Shift:mad:ltoright, copy origin:=xlformatfromleftorabove

The error is "Application defined or object defined error"

The variables are defined in a separate module as public variables, and I do not have any variable called "Columns"


Code:
Option ExplicitSub Offset_Time()


File.Activate
Sheets(1).Select


'Set the value of the Time_Offset variable
If ThisWorkbook.Sheets(1).OLEObjects("optionbutton1").Object.Value = True Then Time_Offset = Cells(26, "E")
If ThisWorkbook.Sheets(1).OLEObjects("optionbutton2").Object.Value = True Then Time_Offset = Cells(27, "E")
If ThisWorkbook.Sheets(1).OLEObjects("optionbutton3").Object.Value = True Then Time_Offset = Cells(28, "E")
If ThisWorkbook.Sheets(1).OLEObjects("optionbutton4").Object.Value = True Then Time_Offset = Cells(29, "E")
If ThisWorkbook.Sheets(1).OLEObjects("optionbutton5").Object.Value = True Then Time_Offset = Cells(30, "E")


'Insert a row and give it a header
Columns("4:4").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(1, 4) = "Time_sec"


'Figure out when the vehicle starts moving, set it equal to a variable
Vehicle_Speed_Col = Application.Match("Vehicle_Speed_Avg_Front_Wheels", Rows("1:1"), 0)
For i = 1 To Quan_Rows_File
    If Cells(i, Vehicle_Speed_Col) > 0 Then
        First_Movement_Line = i
        Exit For
    End If
Next i


'Start populating the new channel
For i = 2 To Quan_Rows_File
    Cells(i, "D") = Time_Offset + (0.1 * (i - First_Movement_Line))
Next i


End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,213,487
Messages
6,113,938
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top