Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Help with search and create code

I am trying to create an alphanumeric value and insert it into a sheet column
'M' based on a combocox selection, I want it to search column 'M' find the
left 2 letters then add 1 number to the value it creates. I have been trying
to create it but keep failing, here is my code

'searches for duplicate MSDS# in column 'M'
dept = Columns(13).Find(What:=CboDept.Value, _
After:=Cells(5000, 13), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
If Me.CboDept.Value = "" Then
End If
If Me.CboDept.Value = dept Then
dept = Me.CboDept.Value & 0 + 1
End If
Exit Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with search and create code

Your description of what you want is not very clear; however, I think this
is it.

Dim X as integer, Prefix as string, HighestNumber as long, ValueDesired as
string
X = 2 'Assuming that your values in col M start at row 2
Prefix = left(range(??).value, 2) 'Use the range to which you set the
comboboxes linked cell. That's where the selected value is stored.
HighestNumber = 0

Do while range("M" & x).value < ""
If left(range("M" & x).value, 2) = prefix then
highestnumber = highestnumber + value(replace(range("M" &
X).value), prefix, ""))
End if
x = x + 1
loop

ValueDesired = prefix & highestnumber + 1

Try this.

Ross

"Mekinnik" wrote in message
...
I am trying to create an alphanumeric value and insert it into a sheet
column
'M' based on a combocox selection, I want it to search column 'M' find the
left 2 letters then add 1 number to the value it creates. I have been
trying
to create it but keep failing, here is my code

'searches for duplicate MSDS# in column 'M'
dept = Columns(13).Find(What:=CboDept.Value, _
After:=Cells(5000, 13), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
If Me.CboDept.Value = "" Then
End If
If Me.CboDept.Value = dept Then
dept = Me.CboDept.Value & 0 + 1
End If
Exit Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Help with search and create code

Mekinnik,

Here try it with this code.

= dept Then


Sub Mekinnik()

Dim iLastRow As Long
Dim look4Me As String
look4Me = Me.CboDept.Value
iLastRow = Range("H" & Range("H:H").Rows.Count).End(xlUp).Row
'change to the column you want to search

Range("H1").Select 'go to the top of the column to begin searching

Do Until iLastRow = -1

If ActiveCell = look4Me Then
dept = Me.CboDept.Value & 0 + 1
Else

End If

iLastRow = iLastRow - 1
ActiveCell.Offset(1, 0).Select
Loop

End Sub

"Mekinnik" wrote:

I am trying to create an alphanumeric value and insert it into a sheet column
'M' based on a combocox selection, I want it to search column 'M' find the
left 2 letters then add 1 number to the value it creates. I have been trying
to create it but keep failing, here is my code

'searches for duplicate MSDS# in column 'M'
dept = Columns(13).Find(What:=CboDept.Value, _
After:=Cells(5000, 13), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
If Me.CboDept.Value = "" Then
End If
If Me.CboDept.Value = dept Then
dept = Me.CboDept.Value & 0 + 1
End If
Exit Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Help with search and create code

Let me try and explain it more clearly. I have a userform with a combobox on
it which gets it values from sheet 'Lists' C2:C10. I would like when the user
selects the value in the combobox and click the add button it will create the
alphanumeric number in column 'M' on sheet 'ProCode', it will search for the
left 2 letter and add 1 to the numerical value.

I tried you code and I have 2 problems

#1 I am not sure how to reference sheet 'Lists' column C2:C10 in the
following line

Prefix = left(range(??).value, 2)

#2 I keep coming up with a compile error for the folling line with the
replace highlighted

highestnumber = highestnumber + value(replace(range("M" &
X).value), prefix, ""))


"Ross Culver" wrote:

Your description of what you want is not very clear; however, I think this
is it.

Dim X as integer, Prefix as string, HighestNumber as long, ValueDesired as
string
X = 2 'Assuming that your values in col M start at row 2
Prefix = left(range(??).value, 2) 'Use the range to which you set the
comboboxes linked cell. That's where the selected value is stored.
HighestNumber = 0

Do while range("M" & x).value < ""
If left(range("M" & x).value, 2) = prefix then
highestnumber = highestnumber + value(replace(range("M" &
X).value), prefix, ""))
End if
x = x + 1
loop

ValueDesired = prefix & highestnumber + 1

Try this.

Ross

"Mekinnik" wrote in message
...
I am trying to create an alphanumeric value and insert it into a sheet
column
'M' based on a combocox selection, I want it to search column 'M' find the
left 2 letters then add 1 number to the value it creates. I have been
trying
to create it but keep failing, here is my code

'searches for duplicate MSDS# in column 'M'
dept = Columns(13).Find(What:=CboDept.Value, _
After:=Cells(5000, 13), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
If Me.CboDept.Value = "" Then
End If
If Me.CboDept.Value = dept Then
dept = Me.CboDept.Value & 0 + 1
End If
Exit Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with search and create code


"Mekinnik" wrote in message
...
Let me try and explain it more clearly. I have a userform with a combobox
on
it which gets it values from sheet 'Lists' C2:C10. I would like when the
user
selects the value in the combobox and click the add button it will create
the
alphanumeric number in column 'M' on sheet 'ProCode', it will search for
the
left 2 letter and add 1 to the numerical value.

I tried you code and I have 2 problems

#1 I am not sure how to reference sheet 'Lists' column C2:C10 in the
following line

Prefix = left(range(??).value, 2)


Did you set a LinkedCell value for your combobox? If so, then reference it
like this: sheets("Lists").range("D2").value
D2 is just an example. Use which ever cell you actually set the LinkedCell
value to.
If you didn't set the linkedcell value then use:
Prefix = me.combobox.selectedtext

What's in C2? Just the two letter codes or something more? And the new
value that you're trying to derive, it that supposed to added to the bottom
of your List?


#2 I keep coming up with a compile error for the folling line with the
replace highlighted

highestnumber = highestnumber + value(replace(range("M" &
X).value), prefix, ""))


Actually, that wouldn't get you what you want anyway. Try this:
dim NextValue as long
NextValue = 0

Do while range("M" & x).value < ""
If left(range("M" & x).value, 2) = prefix then
NextValue = value(replace(range("M" & X).value, prefix, ""))
If nextvalue highestnumber then
highestnumber = nextvalue
end if
End if
x = x + 1
loop

Note the change in the formula above. I had too many parenthesis in the
last one.


"Ross Culver" wrote:

Your description of what you want is not very clear; however, I think
this
is it.

Dim X as integer, Prefix as string, HighestNumber as long, ValueDesired
as
string
X = 2 'Assuming that your values in col M start at row 2
Prefix = left(range(??).value, 2) 'Use the range to which you set the
comboboxes linked cell. That's where the selected value is stored.
HighestNumber = 0

Do while range("M" & x).value < ""
If left(range("M" & x).value, 2) = prefix then
highestnumber = highestnumber + value(replace(range("M" &
X).value), prefix, ""))
End if
x = x + 1
loop

ValueDesired = prefix & highestnumber + 1

Try this.

Ross

"Mekinnik" wrote in message
...
I am trying to create an alphanumeric value and insert it into a sheet
column
'M' based on a combocox selection, I want it to search column 'M' find
the
left 2 letters then add 1 number to the value it creates. I have been
trying
to create it but keep failing, here is my code

'searches for duplicate MSDS# in column 'M'
dept = Columns(13).Find(What:=CboDept.Value, _
After:=Cells(5000, 13), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
If Me.CboDept.Value = "" Then
End If
If Me.CboDept.Value = dept Then
dept = Me.CboDept.Value & 0 + 1
End If
Exit Sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a form to insert a hyerlink.VBA code to create a for karthi Excel Discussion (Misc queries) 0 July 5th 06 11:26 AM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Excel Programming 4 June 15th 05 04:37 PM
Create a search Field within a worksheet to search command buttons Ed P[_2_] Excel Programming 1 December 14th 04 08:04 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed[_18_] Excel Programming 4 May 20th 04 02:08 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Excel Programming 0 May 19th 04 08:11 PM


All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"