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

I have recently ran macro record to get a quick code built to help me set up
for a copy feature I am trying to build. it works fine in the record but
when I place it in a button I get an error on the range line. the code is:
Private Sub CommandButton1_Click()
If Range("a1").Value = "test" Then
Sheets("information").Select
Range("A3:A21").Select
Selection.Copy
Sheets("information sheet").Select
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=
_
xlNone, SkipBlanks:=False, Transpose:=True
End If
End Sub

I get the error on the line Range("A3:A21").Select

Can someone help me understand why I am getting the error?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/201005/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default understanding

The selects and selections are unnecessary. The problem was that VBA likes
to know which sheet it is supposed to be working on. I am not sure if the
names are correct but the syntax will work. Check the sheet names to be
sure there is no typo.


Sheets("information").Range("A3:A21").Copy
Sheets("information sheet").Range("C1") _
.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=True





"Darrell_Sarrasin via OfficeKB.com" <u33691@uwe wrote in message
news:a827455cf280e@uwe...
I have recently ran macro record to get a quick code built to help me set
up
for a copy feature I am trying to build. it works fine in the record but
when I place it in a button I get an error on the range line. the code
is:
Private Sub CommandButton1_Click()
If Range("a1").Value = "test" Then
Sheets("information").Select
Range("A3:A21").Select
Selection.Copy
Sheets("information sheet").Select
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:=
_
xlNone, SkipBlanks:=False, Transpose:=True
End If
End Sub

I get the error on the line Range("A3:A21").Select

Can someone help me understand why I am getting the error?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/201005/1



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default understanding

Awesome thanks!!!

is there a way to get this to auto run based on the selection off a valdation
list? I can get it to run behind the button, but want it to auto run.

Thanks again for your help!!

JLGWhiz wrote:
The selects and selections are unnecessary. The problem was that VBA likes
to know which sheet it is supposed to be working on. I am not sure if the
names are correct but the syntax will work. Check the sheet names to be
sure there is no typo.

Sheets("information").Range("A3:A21").Copy
Sheets("information sheet").Range("C1") _
.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=True

I have recently ran macro record to get a quick code built to help me set
up

[quoted text clipped - 18 lines]

Can someone help me understand why I am getting the error?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/201005/1

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default understanding

Make it event code.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("A1")).Value = "test" Then
Me.Range("A3:A21").Copy
Sheets("information sheet").Range("C1") _
.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End If
Application.CutCopyMode = False
End Sub


Gord Dibben MS Excel MVP


On Tue, 18 May 2010 12:14:26 GMT, "Darrell_Sarrasin via OfficeKB.com"
<u33691@uwe wrote:

Awesome thanks!!!

is there a way to get this to auto run based on the selection off a valdation
list? I can get it to run behind the button, but want it to auto run.

Thanks again for your help!!

JLGWhiz wrote:
The selects and selections are unnecessary. The problem was that VBA likes
to know which sheet it is supposed to be working on. I am not sure if the
names are correct but the syntax will work. Check the sheet names to be
sure there is no typo.

Sheets("information").Range("A3:A21").Copy
Sheets("information sheet").Range("C1") _
.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=True

I have recently ran macro record to get a quick code built to help me set
up

[quoted text clipped - 18 lines]

Can someone help me understand why I am getting the error?


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
Better Understanding Marsh Excel Programming 4 December 30th 09 08:35 PM
Understanding SUMPRODUCT Jordan Excel Worksheet Functions 11 May 25th 06 11:08 PM
Not understanding with/end with davegb Excel Programming 7 March 6th 06 09:42 PM
Not understanding If Not..Then nothing davegb Excel Programming 6 June 14th 05 04:49 PM
Understanding Templates Syed Zeeshan Haider Excel Programming 6 May 25th 05 12:39 AM


All times are GMT +1. The time now is 05:29 PM.

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"