#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Proper code

I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Proper code

Manual

Enter -1 in a empty cell
Copy this cell

Select your cells and right click on them
Choose Paste Special..Multiply
OK

You can do this with VBA also

--
Regards Ron De Bruin
http://www.rondebruin.nl



"JimMay" wrote in message news:H%Ggg.40308$fG3.11689@dukeread09...
I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Proper code

Ron,
Yes -- it is the VBA that I need to do it in;
I tried to record a macro using the manual method
But it failed.
Appreciate any help you could provide.
Jim

"Ron de Bruin" wrote in message
:

Manual

Enter -1 in a empty cell
Copy this cell

Select your cells and right click on them
Choose Paste Special..Multiply
OK

You can do this with VBA also

--
Regards Ron De Bruin
http://www.rondebruin.nl



"JimMay" wrote in message news:H%Ggg.40308$fG3.11689@dukeread09...

I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Proper code

Hi Jim

I use F1 in this example

Range("F1").Value = -1
Range("F1").Copy

Lrow = Range("E" & Rows.Count).End(xlUp).Row
Range("E6:E" & Lrow).PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("F1").Value = ""



--
Regards Ron De Bruin
http://www.rondebruin.nl



"JimMay" wrote in message news:cuHgg.40311$fG3.14888@dukeread09...
Ron,
Yes -- it is the VBA that I need to do it in;
I tried to record a macro using the manual method
But it failed.
Appreciate any help you could provide.
Jim

"Ron de Bruin" wrote in message :

Manual

Enter -1 in a empty cell
Copy this cell

Select your cells and right click on them
Choose Paste Special..Multiply
OK

You can do this with VBA also

--
Regards Ron De Bruin
http://www.rondebruin.nl



"JimMay" wrote in message news:H%Ggg.40308$fG3.11689@dukeread09...

I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Proper code

Option Explicit
Sub testme()

Dim LRow As Long
Dim tempCell As Range
Dim myRng As Range

With ActiveSheet
LRow = .Cells(.Rows.Count, "E").End(xlUp).Row
Set myRng = .Range("e6:e" & LRow)

Set tempCell = .Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 1)
tempCell.Value = -1

tempCell.Copy
myRng.PasteSpecial Paste:=xlPasteAll, _
operation:=xlPasteSpecialOperationMultiply, _
skipblanks:=False, Transpose:=False

tempCell.ClearContents
End With

End Sub


JimMay wrote:

Ron,
Yes -- it is the VBA that I need to do it in;
I tried to record a macro using the manual method
But it failed.
Appreciate any help you could provide.
Jim

"Ron de Bruin" wrote in message
:

Manual

Enter -1 in a empty cell
Copy this cell

Select your cells and right click on them
Choose Paste Special..Multiply
OK

You can do this with VBA also

--
Regards Ron De Bruin
http://www.rondebruin.nl



"JimMay" wrote in message news:H%Ggg.40308$fG3.11689@dukeread09...

I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim



--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Proper code

Hi Jim,

Just another way to skin the proverbial cat:
:
'=============
Public Sub Tester()
Const sFirstCell As String = "E6"

On Error Resume Next
With ActiveSheet.Range(sFirstCell)
.Resize(Rows.Count - .Row + 1). _
SpecialCells(xlConstants, xlNumbers). _
Replace What:="-", Replacement:=""
End With
On Error GoTo 0

End Sub
'<<=============

---
Regards,
Norman

"JimMay" wrote in message
news:H%Ggg.40308$fG3.11689@dukeread09...
I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Proper code

Here's something no quite as cryptic:

Dim rng as Range, cell as Range
Set rng = Range("E6:E" & Lrow)

For Each cell in rng
cell = cell * -1
Next

JimMay wrote:
I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Proper code

Hi Steve,

Here's something no quite as cryptic


It is not clear whether it was one, or all three, of the suggested solutions
which engendered your pejorative description, but none of these strikes me
as cryptic and all avoid the need to loop.

Incidentally, your code would also need to assign a value to the Lrow
variable.

---
Regards,
Norman


"SteveM" wrote in message
oups.com...
Here's something no quite as cryptic:

Dim rng as Range, cell as Range
Set rng = Range("E6:E" & Lrow)

For Each cell in rng
cell = cell * -1
Next




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Proper code

Nothing perjorative intended. You guys are no doubt better at VBA than
I. Let's say more compact then. Are loops a bad thing?

And I assumed he had declared all of the variables in the code he
submitted.

Regards,

SteveM


Norman Jones wrote:
Hi Steve,

Here's something no quite as cryptic


It is not clear whether it was one, or all three, of the suggested solutions
which engendered your pejorative description, but none of these strikes me
as cryptic and all avoid the need to loop.

Incidentally, your code would also need to assign a value to the Lrow
variable.

---
Regards,
Norman


"SteveM" wrote in message
oups.com...
Here's something no quite as cryptic:

Dim rng as Range, cell as Range
Set rng = Range("E6:E" & Lrow)

For Each cell in rng
cell = cell * -1
Next


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Proper code

Hi Steve,

Let's say more compact then. Are loops a bad thing?


Per se, certainly not. However, non-looping methods will often be faster
than the looping equivalent.

And I assumed he had declared all of the variables in the code he
submitted.


The undeclared variable was only mentioned to alert the OP of the need and,
implicitly, to address the issue of compactness.


---
Regards,
Norman




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Proper code

I'm surprised noone suggested using the absolute value function, Abs.

If it is possible (Jim did not specifiy how the cell values are set
initially) set the cell value to Abs("cell value"). This way, there would be
no need to go back again and convert them to their positive counterparts.

If VBA code is required to convert them, then the Abs function is an
alternative to multiplying by -1.

Boog
"JimMay" wrote:

I need (In VBA code) to convert a varying range of values,
Say Range("E6:E" & Lrow) from:
-123
-234
-345
-456

To:

123
234
345
456

But can't quite get it going here;
Can someone show me how?

TIA,

Jim



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
Not Proper! Adam Excel Worksheet Functions 2 September 19th 07 12:08 PM
proper afdmello Excel Discussion (Misc queries) 3 October 11th 05 09:48 AM
VBA Proper Case Code EMoe[_3_] Excel Programming 4 May 25th 05 08:07 PM
proper syntax in code needed Jim May Excel Programming 2 September 19th 04 12:44 AM
Proper case code not working right Juan Excel Programming 3 April 16th 04 11:11 PM


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