Help with \

rogersj

Board Regular
Joined
Aug 13, 2002
Messages
187
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 8/27/2002 by Me
'


If ListBox1 = "Computer" Then

Range("D9").Select
Application.CutCopyMode = False
Selection.Copy
Range("C9").Select
ActiveSheet.Paste

ElseIf ListBox1 = "Monitor" Then

Range("D10").Select
Application.CutCopyMode = False
Selection.Copy
Range("C10").Select
ActiveSheet.Paste

End If

End Sub


Welp, If my list box has 'Computer' selected, and the Macro buttom is hit, it should copy the word Computer "D9" and paste it in "C9"

Im doing something wrong, please help me!
This message was edited by rogersj on 2002-08-27 17:33
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What error are you getting ? because the first thing that comes to mind is that you're code says that you should copy D9 and paste it to C9 instead of D5 and C5
 
Upvote 0
Sorry. I had a typo in the last sentence.. I get no error at all. .. It just sits there.
 
Upvote 0
See if this helps. I find when I run into code problems, coding the long way helps sort out the problems. The code below should work in your context, just stack the if block for as many tests as you need one after another. JSW

Sub myCopy()
If [D9].Value = "Computer" Then
Worksheets("Sheet1").Range("D9").Select
Selection.Copy
Worksheets("Sheet1").Range("C9").Select
ActiveSheet.Paste
End If
End Sub
 
Upvote 0
Also, I tested your code with a listBox on sheet1 and the listBox property "FillRange"=D9 which contained the value Computer, then put your code in the ListBox1_Click event sub. Clicked the listBox and your code copied "Computer" to "C9".

Did you run your code the way I indicated above?

Or did you run the code a different way?

Did you load the listBox fillRange a different way, other than the ListBox1 properties FillRange item?
JSW

_________________<INPUT type="JSW" value=" Excel On... Coder's!" ID=Text1><spanstyle='font-size:36.0pt;color:#FFCC00'>JSW<o:p></o:p></span>[/b]</p><spanstyle='font-size:36.0pt;color:#FFCC00'>Try and try again, " The way of the coder!"<o:p></o:p></span>[/b]
This message was edited by Joe Was on 2002-08-27 18:14
 
Upvote 0
That may work, but I want to copy whats selected in Listbox1, and then paste it elsewhere.

whats why i have that i statement

If listbox1 = computer then
copy d9 (thats where "Computer" is, from the listbox 1 input range is)

and paste from d9 to d8
 
Upvote 0
This is how you do that!

Private Sub ListBox1_Click()
If ListBox1 = "Computer" Then
[C9] = ListBox1.Value
End If

If ListBox1 = "Monitor" Then
[C10] = ListBox1.Value
End If
End Sub
 
Upvote 0
Have you tried using indexes to check the contents of the listBox.

E.g

If ListBox1.ListIndex = 0 then

ElseIF ListBox1.ListIndex = 1 then

etc

This means you just have to know which order Computer and Monitor are loaded in ths List Box.
 
Upvote 0

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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