Input Box not working in VBA

some_evil

New Member
Joined
Feb 19, 2014
Messages
33
Office Version
  1. 365
Platform
  1. Windows
hi Guys,

I am trying to play with vbs again, and what I am trying to achieve is that a pop up box appears when I run the macro, the user enters some text (a name or something) and then the macro fills this name down the sheet.

I have the line below it (commented out below) working fine, but I am trying to get a little fancier and I keep getting an error 'Compile Error: Object Required'.

Can someone see where I am going wrong in the below code??
Thanks


Code:
Sub SewerStructures_InsertFormula_AssetDescription()
     With ActiveSheet
     Dim inputData As String
     Set inputData = Application.InputBox("Enter Name:", "Collect User Input", Type:=2)
        .Range("B2:B" & Range("F" & Rows.Count).End(xlUp).Row).Formula = inputData

'       .Range("B2:B" & Range("F" & Rows.Count).End(xlUp).Row).Formula = "=G2&IF(I2="""","""","" - Manhole # ""&I2)&IF(N2="""","""","" - ""&N2)"


    End With
End Sub
 

Excel Facts

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

I am trying to play with vbs again, and what I am trying to achieve is that a pop up box appears when I run the macro, the user enters some text (a name or something) and then the macro fills this name down the sheet.

I have the line below it (commented out below) working fine, but I am trying to get a little fancier and I keep getting an error 'Compile Error: Object Required'.

Can someone see where I am going wrong in the below code??
Thanks


Code:
Sub SewerStructures_InsertFormula_AssetDescription()
     With ActiveSheet
     Dim inputData As String
     [COLOR=#FF0000][B]Set [/B][/COLOR]inputData = Application.InputBox("Enter Name:", "Collect User Input", Type:=2)
        .Range("B2:B" & Range("F" & Rows.Count).End(xlUp).Row).Formula = inputData

'       .Range("B2:B" & Range("F" & Rows.Count).End(xlUp).Row).Formula = "=G2&IF(I2="""","""","" - Manhole # ""&I2)&IF(N2="""","""","" - ""&N2)"  
    End With
End Sub
Remove the red highlighted word... you declard inputData as a String variable and the keyword Set is used only with Object type variables.
 
Upvote 0
You are using Set when you should be using Let.
Code:
Let inputData = Application.InputBox("Enter Name:", "Collect User Input", Type:=2)
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,260
Members
449,149
Latest member
mwdbActuary

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