ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Code not working and can't see why (https://www.excelbanter.com/excel-discussion-misc-queries/2767-code-not-working-cant-see-why.html)

Steve

Code not working and can't see why
 
I have the code below attached to a command button (GoButton) on a
worksheet called "Main". For some reason, the code shuts down and wants
to debug any line with 'Range...' in it. Does anyone know why?

Private Sub GoButton_Click()
Worksheets("InfoLoader").Activate
Range("W1:W50").Select
Selection.Value = ""
Range("E7").Select
ActiveCell.Value = ComboBox2.Value
Range("E2").Select
ActiveCell.Value = ComboBox3.Value
Range("B" & Range("F2").Value + 14 & ":B" _
& Range("F4").Value + 14).Copy Destination:=Range("W1")
End Sub

Thanks in advance

Steve


Jerry W. Lewis

Possibly there is some abiguity in the context of the button click. Try
the following. Also, given the With block, the
Worksheets("InfoLoader").Activate
may not be necessary.

Private Sub GoButton_Click()
Worksheets("InfoLoader").Activate
With Worksheets("InfoLoader")
..Range("W1:W50") = ""
..Range("E7") = ComboBox2.Value
..Range("E2") = ComboBox3.Value
..Range("B" & .Range("F2").Value + 14 & ":B" _
& .Range("F4").Value + 14).Copy Destination:=.Range("W1")
End With
End Sub

Jerry

Steve wrote:

I have the code below attached to a command button (GoButton) on a
worksheet called "Main". For some reason, the code shuts down and wants
to debug any line with 'Range...' in it. Does anyone know why?

Private Sub GoButton_Click()
Worksheets("InfoLoader").Activate
Range("W1:W50").Select
Selection.Value = ""
Range("E7").Select
ActiveCell.Value = ComboBox2.Value
Range("E2").Select
ActiveCell.Value = ComboBox3.Value
Range("B" & Range("F2").Value + 14 & ":B" _
& Range("F4").Value + 14).Copy Destination:=Range("W1")
End Sub

Thanks in advance

Steve




Steve

That did the trick.

Thanks a lot for that.

Steve


Jerry W. Lewis

You're welcome. Glad it helped.

Jerry

Steve wrote:

That did the trick.

Thanks a lot for that.

Steve




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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com