Object variable not set error

HimanshuK

New Member
Joined
Jun 14, 2016
Messages
23
HI There,

I am trying the below code to use a dynamic range for lastfillrange in a combobox. It gives an error of Object variable not set

dont know what happened!! Can anyone help?

Private Sub ComboBox1_Change()
Dim lastrow As Long
Dim dyrange As Range
lastrow = Sheets("BG").Range("E7").End(xlUp).Row
dyrange = Sheets("BG").Range("E7:E" & lastrow)
ComboBox1.ListFillRange = dyrange


End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,
Thanks for your response. It really helped!!!

But the code is not running

Below is the code am using, with minor changes

Option Explicit
Private Sub ComboBox1_Change()
Dim lastrow As Long
Dim dyrange As Range
Dim sht As Worksheet
Set sht = Worksheets("BG")
With sht
lastrow = .Range("E7").End(xlUp).Row
Set dyrange = .Range("E7:E" & lastrow)
End With


ComboBox1.ListFillRange = "=dyrange"


End Sub
 
Upvote 0
Put this in the module of the sheet (Input?) that has the combobox on it.
Code:
Private Sub Worksheet_Activate()
Dim lastrow As Long
Dim dyrange As Range

    lastrow = Sheets("BG").Range("E" & Rows.Count).End(xlUp).Row
    Set dyrange = Sheets("BG").Range("E7:E" & lastrow)
    ComboBox1.List = dyrange.Value

End Sub
 
Upvote 0
Hi Norrie thanks for your response. This code gives a run-time error 424 - object required and marks "ComboBox1.List = dyrange.Value" yellow
 
Upvote 0
Where exactly did you put the code?

Also, how did you create the combobox?
 
Upvote 0
I put the code in the module of sheet (Input), the sheet has the combobox. I used activex controls to make the combobox.

I just used the comboboxlist script from your code with the initial code i was writing and it worked.

Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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