Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default What is wrong with this code ??

Don't know why this code won't work
Trying to define array ("M1:O1") thru ("M5:O5")
and input results to a child sheet
The code below this and before the 'NEXT' statement works fine.

For g = 1 to 5
Set gml = Sheets("Input").Range(cells(g,13),cells(g,15))
next

Anyhelp is appreciated
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default What is wrong with this code ??

Try setting the worksheet of the cells in the Range.

--
Disregard, this is so I can find my post later.
***postedbyJay***


"cgnotrom" wrote:

Don't know why this code won't work
Trying to define array ("M1:O1") thru ("M5:O5")
and input results to a child sheet
The code below this and before the 'NEXT' statement works fine.

For g = 1 to 5
Set gml = Sheets("Input").Range(cells(g,13),cells(g,15))
next

Anyhelp is appreciated
Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default What is wrong with this code ??

Maybe

Set gml = Sheets("Input").Range(Cells(1, 13), Cells(5, 15))

Mike

"cgnotrom" wrote:

Don't know why this code won't work
Trying to define array ("M1:O1") thru ("M5:O5")
and input results to a child sheet
The code below this and before the 'NEXT' statement works fine.

For g = 1 to 5
Set gml = Sheets("Input").Range(cells(g,13),cells(g,15))
next

Anyhelp is appreciated
Chris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default What is wrong with this code ??

Dim G as long
dim gml as range

with sheets("input")
for g = 1 to 5
set gml = .range(.cells(g,13), .cells(g,15))
'do something with gml here???
next g
end with

or
for g = 1 to 5
set gml = sheets("sheet1").cells(g,13).resize(1,3)
'do something with gml here???
next g




cgnotrom wrote:

Don't know why this code won't work
Trying to define array ("M1:O1") thru ("M5:O5")
and input results to a child sheet
The code below this and before the 'NEXT' statement works fine.

For g = 1 to 5
Set gml = Sheets("Input").Range(cells(g,13),cells(g,15))
next

Anyhelp is appreciated
Chris


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default What is wrong with this code ??

Notice the placement of the dots in front of .range and .cells
Not quite sure what you want here. As shown, you get 1 in all 15 cells.
Changing the comment to the next to last line gets you only 3 on row 5

Sub doit()
For g = 1 To 5
With Sheets("Input")
Set gml = .Range(.Cells(g, 13), .Cells(g, 15))
gml.Value = 1
End With
Next
'gml.Value = 1
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"cgnotrom" wrote in message
...
Don't know why this code won't work
Trying to define array ("M1:O1") thru ("M5:O5")
and input results to a child sheet
The code below this and before the 'NEXT' statement works fine.

For g = 1 to 5
Set gml = Sheets("Input").Range(cells(g,13),cells(g,15))
next

Anyhelp is appreciated
Chris




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default What is wrong with this code ??


Thankyou Dave
The second suggestion works great..the .resize comand did the trick
and has saved me many 'if then' statements.
Thanks again
Chris
"Dave Peterson" wrote:

Dim G as long
dim gml as range

with sheets("input")
for g = 1 to 5
set gml = .range(.cells(g,13), .cells(g,15))
'do something with gml here???
next g
end with

or
for g = 1 to 5
set gml = sheets("sheet1").cells(g,13).resize(1,3)
'do something with gml here???
next g




cgnotrom wrote:

Don't know why this code won't work
Trying to define array ("M1:O1") thru ("M5:O5")
and input results to a child sheet
The code below this and before the 'NEXT' statement works fine.

For g = 1 to 5
Set gml = Sheets("Input").Range(cells(g,13),cells(g,15))
next

Anyhelp is appreciated
Chris


--

Dave Peterson

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
What's wrong with this code? xavi garriga Excel Programming 3 January 10th 08 09:12 AM
What is wrong with my code?? Mekinnik Excel Programming 4 October 2nd 07 03:56 PM
What is wrong with the code? Eric Excel Discussion (Misc queries) 2 September 13th 07 10:36 AM
What is wrong with this code? sungen99[_32_] Excel Programming 3 October 12th 05 08:12 PM
HELP! What's wrong with my code? Sethaholic[_5_] Excel Programming 0 July 11th 05 07:43 PM


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