Error 400?

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
I am writing a simple string of code and continue to get an Error that reads "400." I found a thread that addressed this, but thought maybe it had something to do with the code.

Sub Worksheet_S10()


'Activate Workbook
Workbooks("Workbook1.xlsm").Activate
'Activate Worksheet
Workbooks("Workbook1").Sheets("Sheet1").Activate


'Categorize as Insured or Uninsured
Range("B10:B" & LastRow).Formula = "=IF(RC[7]>1,""Insured"",""Uninsured"")"




End Sub


Basically all I want it to do is to open the sheet (which it does) and copy enter and copy the formula to all cells in column B. All help is appreciated!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You haven't defined what LastRow is. Try:
Code:
Sub Worksheet_S10()
    Dim lastRow As Long
    lastRow = Range("B" & Rows.Count).End(xlUp).Row
    Sheets("Sheet1").Range("B10:B" & lastRow).Formula = "=IF(RC[7]>1,""Insured"",""Uninsured"")"
End Sub
 
Upvote 0
Hi & welcome to the board.
Couple of problems.
1) In the line activating the sheet you have not specified the workbook extension. (This may not be a problem, depending on your folder settings)
2) You have not given LastRow a value, so it's trying to insert the formula from row 0, which doesn't exist.
Try
Code:
Sub Worksheet_S10()

Dim LastRow As Long
'Activate Workbook
Workbooks("Workbook1.xlsm").Activate
'Activate Worksheet
Workbooks("Workbook1.xlsm").Sheets("Sheet1").Activate

LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Categorize as Insured or Uninsured
Range("B10:B" & LastRow).Formula = "=IF(RC[7]>1,""Insured"",""Uninsured"")"




End Sub
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

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