Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setup Cells Without Looping


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Setup Cells Without Looping

Maybe I didn't make enough tests, but the one I ran worked. I set A1:C1
number format to 0.00 then ran the macro and it changed the numbers in A3:C3
to 0.00 format.

"Gary''s Student" wrote:

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Setup Cells Without Looping

I ran several more tests and could not make it hiccup. The code seems to
work. Must be another problem.

"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Setup Cells Without Looping

it doesn't work with mixed formats, and I think that's the point GS is making

"JLGWhiz" wrote:

I ran several more tests and could not make it hiccup. The code seems to
work. Must be another problem.

"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!
--
Gary''s Student - gsnu200832


"JLGWhiz" wrote:

Maybe I didn't make enough tests, but the one I ran worked. I set A1:C1
number format to 0.00 then ran the macro and it changed the numbers in A3:C3
to 0.00 format.

"Gary''s Student" wrote:

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

Is the Value property somehow "special"?
The only way I get the formats to set up is if I loop cell-by-cell.
What am I doing wrong?
--
Gary''s Student - gsnu200832


"Mike H" wrote:

it doesn't work with mixed formats, and I think that's the point GS is making

"JLGWhiz" wrote:

I ran several more tests and could not make it hiccup. The code seems to
work. Must be another problem.

"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Setup Cells Without Looping

GS,

Like yourself I could do it other ways but I'm still trying to understand
why this doesn't work. I was working on the same one as yourself 1,2 &3
decimal places to try and understand what's going on

Mike

"Gary''s Student" wrote:

Is the Value property somehow "special"?
The only way I get the formats to set up is if I loop cell-by-cell.
What am I doing wrong?
--
Gary''s Student - gsnu200832


"Mike H" wrote:

it doesn't work with mixed formats, and I think that's the point GS is making

"JLGWhiz" wrote:

I ran several more tests and could not make it hiccup. The code seems to
work. Must be another problem.

"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Setup Cells Without Looping

Not all properties can be retrieved this way (as you've seen).

Why? Because MS said so. <bg

Gary''s Student wrote:

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Setup Cells Without Looping

hi
i did some test too. it works if all the formats are the same but doesn't if
the formats are different.
using xl02 on xp here.
seems the xl code allows for the transfer of different values range to range
but not different formats. odd.
i'm at a loss. but i will just make note of this as something learned.

Regards
FSt1

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Setup Cells Without Looping

This worked OK, I guess Dave is right, Microsoft didn't want it to work the
other way.

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r1.Copy
r2.PasteSpecial Paste:=xlPasteFormats
End Sub

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile: http://www.thecodecage.com/forumz/member.php?userid=117
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=60083


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Setup Cells Without Looping

When dealing with the contents of cells, Excel/VBA can extract values, text,
or formulas in an array. Any other property cannot be extracted as an array,
but merely as a scalar value. To get this scalar, VBA uses the property
value for the top left cell.

Why not use Copy Paste Special Values?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"FSt1" wrote in message
...
hi
i did some test too. it works if all the formats are the same but doesn't
if
the formats are different.
using xl02 on xp here.
seems the xl code allows for the transfer of different values range to
range
but not different formats. odd.
i'm at a loss. but i will just make note of this as something learned.

Regards
FSt1

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile:
http://www.thecodecage.com/forumz/member.php?userid=117
View this thread:
http://www.thecodecage.com/forumz/sh...ad.php?t=60083




  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Setup Cells Without Looping

DOH!! I meant Copy Paste Special Formats!

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Jon Peltier" wrote in message
...
When dealing with the contents of cells, Excel/VBA can extract values,
text, or formulas in an array. Any other property cannot be extracted as
an array, but merely as a scalar value. To get this scalar, VBA uses the
property value for the top left cell.

Why not use Copy Paste Special Values?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"FSt1" wrote in message
...
hi
i did some test too. it works if all the formats are the same but doesn't
if
the formats are different.
using xl02 on xp here.
seems the xl code allows for the transfer of different values range to
range
but not different formats. odd.
i'm at a loss. but i will just make note of this as something learned.

Regards
FSt1

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile:
http://www.thecodecage.com/forumz/member.php?userid=117
View this thread:
http://www.thecodecage.com/forumz/sh...ad.php?t=60083






  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Setup Cells Without Looping

hi
Copy Paste Special Formats! may be the way. as stated, i'll write it up
to something learned today. thanks for the explination.

Regards
FSt1

"Jon Peltier" wrote:

DOH!! I meant Copy Paste Special Formats!

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Jon Peltier" wrote in message
...
When dealing with the contents of cells, Excel/VBA can extract values,
text, or formulas in an array. Any other property cannot be extracted as
an array, but merely as a scalar value. To get this scalar, VBA uses the
property value for the top left cell.

Why not use Copy Paste Special Values?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"FSt1" wrote in message
...
hi
i did some test too. it works if all the formats are the same but doesn't
if
the formats are different.
using xl02 on xp here.
seems the xl code allows for the transfer of different values range to
range
but not different formats. odd.
i'm at a loss. but i will just make note of this as something learned.

Regards
FSt1

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile:
http://www.thecodecage.com/forumz/member.php?userid=117
View this thread:
http://www.thecodecage.com/forumz/sh...ad.php?t=60083









  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

Thank you Jon.

I guess it is the way it is.

Thank you all for taking the time to help me!
--
Gary''s Student - gsnu200832


"FSt1" wrote:

hi
Copy Paste Special Formats! may be the way. as stated, i'll write it up
to something learned today. thanks for the explination.

Regards
FSt1

"Jon Peltier" wrote:

DOH!! I meant Copy Paste Special Formats!

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Jon Peltier" wrote in message
...
When dealing with the contents of cells, Excel/VBA can extract values,
text, or formulas in an array. Any other property cannot be extracted as
an array, but merely as a scalar value. To get this scalar, VBA uses the
property value for the top left cell.

Why not use Copy Paste Special Values?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"FSt1" wrote in message
...
hi
i did some test too. it works if all the formats are the same but doesn't
if
the formats are different.
using xl02 on xp here.
seems the xl code allows for the transfer of different values range to
range
but not different formats. odd.
i'm at a loss. but i will just make note of this as something learned.

Regards
FSt1

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile:
http://www.thecodecage.com/forumz/member.php?userid=117
View this thread:
http://www.thecodecage.com/forumz/sh...ad.php?t=60083







  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

Thank you Dave. I am slowly building an understanding of what
properites/methods need a loop and which do not.
--
Gary''s Student - gsnu200832


"Dave Peterson" wrote:

Not all properties can be retrieved this way (as you've seen).

Why? Because MS said so. <bg

Gary''s Student wrote:

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx


--

Dave Peterson

  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Setup Cells Without Looping

The only way I know them is to try them (well, except for .value).

Gary''s Student wrote:

Thank you Dave. I am slowly building an understanding of what
properites/methods need a loop and which do not.
--
Gary''s Student - gsnu200832

"Dave Peterson" wrote:

Not all properties can be retrieved this way (as you've seen).

Why? Because MS said so. <bg

Gary''s Student wrote:

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx


--

Dave Peterson


--

Dave Peterson
  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Setup Cells Without Looping

..Value, .Text, and .Formula, but I've had the unfortunate experience to
discover that writing an array to a range as .Formula does not work as
expected in some language versions of Excel 2003 (the problem may be more
widespread). I tested on my machine, and it worked fine. The client reported
problems. I could see that his sheet had the wrong formulas. I tried with
his sheet and it worked. Then I had him do it while I watched over
GoToMeeting, so I could validate the array contents (which were correct),
watch the assignment of .Formulas, and immediately check the formulas, which
were wrong: all cells assumed the formula intended for the top left cell. So
I had to resort to a loop.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Dave Peterson" wrote in message
...
The only way I know them is to try them (well, except for .value).

Gary''s Student wrote:

Thank you Dave. I am slowly building an understanding of what
properites/methods need a loop and which do not.
--
Gary''s Student - gsnu200832

"Dave Peterson" wrote:

Not all properties can be retrieved this way (as you've seen).

Why? Because MS said so. <bg

Gary''s Student wrote:

If I enter data in A1 thru C1 and run:

Sub sample1()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.Value = r1.Value
End Sub

The values get correctly setup in A3 thru C3, but if I run:

Sub sample2()
Set r1 = Range("A1:C1")
Set r2 = Range("A3:C3")
r2.NumberFormat = r1.NumberFormat
End Sub

the formats do not get setup. Why?
--
Gary''s Student - gsnu2007xx

--

Dave Peterson


--

Dave Peterson



  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Setup Cells Without Looping

PasteSpecialFormats also pastes the font-type, the font color, the background
color, the alignment, the borders, etc. All I want is the NuberFormat copied.

I will use cell-by-cell.
--
Gary''s Student - gsnu200832


"Jon Peltier" wrote:

DOH!! I meant Copy Paste Special Formats!

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Jon Peltier" wrote in message
...
When dealing with the contents of cells, Excel/VBA can extract values,
text, or formulas in an array. Any other property cannot be extracted as
an array, but merely as a scalar value. To get this scalar, VBA uses the
property value for the top left cell.

Why not use Copy Paste Special Values?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"FSt1" wrote in message
...
hi
i did some test too. it works if all the formats are the same but doesn't
if
the formats are different.
using xl02 on xp here.
seems the xl code allows for the transfer of different values range to
range
but not different formats. odd.
i'm at a loss. but i will just make note of this as something learned.

Regards
FSt1

"Gary''s Student" wrote:

Strange I still can't get it to work.

I formatted A1 with one decimal place
I formatted B1 with two decimal places
I formatted C1 with three decimal places

after I run sample1 I get:

1.0 1.00 1.000

1 1 1

after I run sample2 nothing changes !?!

--
Gary''s Student - gsnu200832


"Stringer" wrote:


I copied your code and set
A1:C1 as Date
A3:C3 as text
Ran the code
A3:C3 became Formatted as date


--
Stringer
------------------------------------------------------------------------
Stringer's Profile:
http://www.thecodecage.com/forumz/member.php?userid=117
View this thread:
http://www.thecodecage.com/forumz/sh...ad.php?t=60083







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
UDF setup for a range of cells John Excel Programming 4 April 28th 06 07:39 PM
Looping through Cells Bill Excel Programming 1 March 2nd 06 06:35 PM
Looping through cells using VBA Ann Excel Programming 2 December 22nd 05 12:05 AM
How can i setup tab order of cells the way i want them? MRD Setting up and Configuration of Excel 1 May 12th 05 08:38 PM
Looping on Cells with $x$y D.Parker Excel Programming 4 March 25th 05 11:31 AM


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"