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
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,048
Office Version
  1. 365
Platform
  1. Windows
Dave

Where in the code are you 'accessing' the combobox value?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,048
Office Version
  1. 365
Platform
  1. Windows
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?
 

not very bright dave

Board Regular
Joined
Dec 20, 2004
Messages
244

ADVERTISEMENT

Just a number, no other characters. The numbers in the combobox are definitely represented in the range the loop is searching.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,048
Office Version
  1. 365
Platform
  1. Windows
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?
 

not very bright dave

Board Regular
Joined
Dec 20, 2004
Messages
244

ADVERTISEMENT

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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,048
Office Version
  1. 365
Platform
  1. Windows
Dave

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

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

Watch MrExcel Video

Forum statistics

Threads
1,118,168
Messages
5,570,652
Members
412,335
Latest member
cinciri99
Top