Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Combobox question

Hi there, Im still pretty much a novice at this so please be gentle!
Ive been asked to automate the inputting into a stock file so I set up a
very basic sheet first (The actual file has 7 inputted columns and will be
run from a userform):
A
1 5001 100
2
3
4 5000 0
5 5001 100
......
10 5006 0

The macro I wrote was:
Public Sub QtyEnter()
Dim ThisCode, CodeRange As Range
Set ThisCode = Range("a1")
lastrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
Set CodeRange = Range("a4:a" & lastrow)
For Each c In CodeRange
If c.Value = ThisCode.Value Then
c.Offset(0, 1) = ThisCode.Offset(0, 1)
End If
Next
End Sub

Which works, so then I put a Combox(linked to the codes), a Textbox(for the
Qty) & Commandbutton with the code:
Public Sub QtyEnter1()
Range("A1") = ComboBox1.Value
Range("B1") = TextBox2.Value * 1
Call QtyEnter
End Sub

Which also works, so I tried combining the two:
Public Sub QtyEnter2()
Dim ThisCode, CodeRange As Range
Set ThisCode = ComboBox1.Value
lastrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
Set CodeRange = Range("a4:a" & lastrow)
For Each c In CodeRange
If c.Value = ThisCode.Value Then
c.Offset(0, 1) = TextBox2.Value * 1
End If
Next
End Sub

Which doesnt work (Object required at Set Thiscode) I know I Should be
Dimming ThisCode as something but nothing seems to work.
Help please!!

Many thanks
Paul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default Combobox question

Public Sub QtyEnter2()
Dim LookupValue as Variant, CodeRange As Range
Dim LastRow as Long, c as Range
LookupValue = ComboBox1.Value
LastRow = Range("A65536").End(xlUp).Row
Set CodeRange = Range("a4:a" & lastrow)
For Each c In CodeRange.Cells
If c.Value = LookupValue Then
c.Offset(0, 1).Value = TextBox2.Value * 1 ''?
End If
Next
End Sub

--
Jim
"Paul" wrote in message
...
| Hi there, I'm still pretty much a novice at this so please be gentle!
| I've been asked to automate the inputting into a stock file so I set up a
| very basic sheet first (The actual file has 7 inputted columns and will be
| run from a userform):
| A
| 1 5001 100
| 2
| 3
| 4 5000 0
| 5 5001 100
| .....
| 10 5006 0
|
| The macro I wrote was:
| Public Sub QtyEnter()
| Dim ThisCode, CodeRange As Range
| Set ThisCode = Range("a1")
| lastrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
| Set CodeRange = Range("a4:a" & lastrow)
| For Each c In CodeRange
| If c.Value = ThisCode.Value Then
| c.Offset(0, 1) = ThisCode.Offset(0, 1)
| End If
| Next
| End Sub
|
| Which works, so then I put a Combox(linked to the codes), a Textbox(for
the
| Qty) & Commandbutton with the code:
| Public Sub QtyEnter1()
| Range("A1") = ComboBox1.Value
| Range("B1") = TextBox2.Value * 1
| Call QtyEnter
| End Sub
|
| Which also works, so I tried combining the two:
| Public Sub QtyEnter2()
| Dim ThisCode, CodeRange As Range
| Set ThisCode = ComboBox1.Value
| lastrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
| Set CodeRange = Range("a4:a" & lastrow)
| For Each c In CodeRange
| If c.Value = ThisCode.Value Then
| c.Offset(0, 1) = TextBox2.Value * 1
| End If
| Next
| End Sub
|
| Which doesn't work (Object required at Set Thiscode) I know I Should be
| Dimming ThisCode as something but nothing seems to work.
| Help please!!
|
| Many thanks
| Paul
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Combobox question

Jim,
Many thanks, that didn't work (nothing happened) but by adapting it to:
Public Sub QtyEnter2()
Dim LookupValue As Integer, CodeRange As Range
LookupValue = ComboBox1.Value
LastRow = Range("A65536").End(xlUp).Row
Set CodeRange = Range("a4:a" & LastRow)
For Each c In CodeRange.Cells
If c.Value = LookupValue Then
c.Offset(0, 1).Value = TextBox2.Value * 1
End If
Next
End Sub

It works! Thanks for pointing me in the right direction
Paul

"Jim Rech" wrote:

Public Sub QtyEnter2()
Dim LookupValue as Variant, CodeRange As Range
Dim LastRow as Long, c as Range
LookupValue = ComboBox1.Value
LastRow = Range("A65536").End(xlUp).Row
Set CodeRange = Range("a4:a" & lastrow)
For Each c In CodeRange.Cells
If c.Value = LookupValue Then
c.Offset(0, 1).Value = TextBox2.Value * 1 ''?
End If
Next
End Sub

--
Jim
"Paul" wrote in message
...
| Hi there, I'm still pretty much a novice at this so please be gentle!
| I've been asked to automate the inputting into a stock file so I set up a
| very basic sheet first (The actual file has 7 inputted columns and will be
| run from a userform):
| A
| 1 5001 100
| 2
| 3
| 4 5000 0
| 5 5001 100
| .....
| 10 5006 0
|
| The macro I wrote was:
| Public Sub QtyEnter()
| Dim ThisCode, CodeRange As Range
| Set ThisCode = Range("a1")
| lastrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
| Set CodeRange = Range("a4:a" & lastrow)
| For Each c In CodeRange
| If c.Value = ThisCode.Value Then
| c.Offset(0, 1) = ThisCode.Offset(0, 1)
| End If
| Next
| End Sub
|
| Which works, so then I put a Combox(linked to the codes), a Textbox(for
the
| Qty) & Commandbutton with the code:
| Public Sub QtyEnter1()
| Range("A1") = ComboBox1.Value
| Range("B1") = TextBox2.Value * 1
| Call QtyEnter
| End Sub
|
| Which also works, so I tried combining the two:
| Public Sub QtyEnter2()
| Dim ThisCode, CodeRange As Range
| Set ThisCode = ComboBox1.Value
| lastrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
| Set CodeRange = Range("a4:a" & lastrow)
| For Each c In CodeRange
| If c.Value = ThisCode.Value Then
| c.Offset(0, 1) = TextBox2.Value * 1
| End If
| Next
| End Sub
|
| Which doesn't work (Object required at Set Thiscode) I know I Should be
| Dimming ThisCode as something but nothing seems to work.
| Help please!!
|
| Many thanks
| Paul
|



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
another combobox question teepee Excel Programming 2 May 13th 07 01:01 AM
combobox question Bri[_3_] Excel Programming 0 February 18th 06 02:51 PM
Combobox question lc Excel Programming 4 September 6th 05 03:40 PM
Combobox Question Andy Excel Programming 2 July 26th 05 04:52 PM
combobox question JT[_2_] Excel Programming 2 February 15th 05 04:32 PM


All times are GMT +1. The time now is 12:16 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"