Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set range to value from another sheet
What's wrong with this code?
Range("Sheet1!B4:AE4") = Cells(2, 1) This is written in the Sheet2 code, and it's supposed to change a range of cells on Sheet1 to a single value set on Sheet2. I get the 1004 error (i.e. undefined error). Gustaf |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set range to value from another sheet
Hi Gustaf
I'm not sure if you can apply a value to a whole range without iterating through it but the code below will do what you want Option Explicit Dim MyCell, MyRng As Range Dim MyStr As String Private Sub CommandButton1_Click() Set MyRng = Sheets("Sheet1").[B4:AE4] MyStr = Cells(2, 1).Value For Each MyCell In MyRng MyCell.Value = MyStr Next End Sub Hope this helps Steve |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set range to value from another sheet
Incidental wrote:
I'm not sure if you can apply a value to a whole range without iterating through it but the code below will do what you want If done on the same sheet, you can apply a value to a whole range. So this is something that happens only when you try apply it on another sheet. But thanks for the solution. I'll try that. Gustaf |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set range to value from another sheet
Sheet1.Range("B4:AE4").Value = Cells(2, 1).Value
-- Tim Zych SF, CA "Gustaf" wrote in message ... What's wrong with this code? Range("Sheet1!B4:AE4") = Cells(2, 1) This is written in the Sheet2 code, and it's supposed to change a range of cells on Sheet1 to a single value set on Sheet2. I get the 1004 error (i.e. undefined error). Gustaf |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Set range to value from another sheet
Tim Zych wrote:
Sheet1.Range("B4:AE4").Value = Cells(2, 1).Value Thank you! That works. Gustaf |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Filter Range on Sheet B Based on List on Sheet A | Excel Discussion (Misc queries) | |||
How do I edit a selected range then copy the range into an new sheet??? | Excel Programming | |||
HELP CONSOLIDATING SAME RANGE EACH SHEET TO SEPARATE SHEET AND RANGE | Excel Discussion (Misc queries) | |||
HELP CONSOLIDATING SAME RANGE EACH SHEET TO SEPARATE SHEET AND RANGE | Excel Programming | |||
HELP CONSOLIDATING SAME RANGE EACH SHEET TO SEPARATE SHEET AND RANGE | Excel Worksheet Functions |