Loop using combobox value

not very bright dave

Board Regular
Joined
Dec 20, 2004
Messages
244
Hi guys

I'm looping through a number of rows and copying any cells that meet the criteria in a combobox and pasting on another worksheet. It works fine if I send the combobox value to a cell and get the code to look at that but when I try to get it to look at the value in the combobox, it messes up. I'm guessing it must be something to do with the loop re-accessing the combobox value each time around. Does anyone have any ideas?

Thanks

Dave

finalrow = Cells(65536, 1).End(xlUp).Row
For i = 1 To finalrow
Worksheets("sheet2").Activate
Cells(i, 1).Select
If Cells(i, 1).Value = Userform7.Combobox1.Value Then
Selection.Copy
Worksheets("sheet3").Activate
Cells(65536, 1).Select
Selection.End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
End If
Worksheets("sheet4").Activate
Next i
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Dave

Where in the code are you 'accessing' the combobox value?
 
Upvote 0
Have you checked that the value from the combobox is what you expect?

Are there any leading/trailing spaces either on the worksheet or in the combobox?
 
Upvote 0
And have you checked that the value in the code is correct?
Code:
Msgbox Userform7.Combobox1.Value
What do you have in the combobox? Does it only have 1 column?
 
Upvote 0
The column (column A) that is being looped through is simply a list of record numbers (1 through to infinty). The user is simply choosing from a list of record numbers in the combobox. I will eventually add an offset selection so the whole record (all 12 columns of data) is returned on the results sheet.
 
Upvote 0
Dave

I'm afraid that I can't really suggest anything else.

By the way are you sure your numbers goto inifinity?:)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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