PC Review


Reply
Thread Tools Rate Thread

Convert cell contents to number

 
 
Jazz
Guest
Posts: n/a
 
      4th Dec 2009
I would like to convert all the cells with contents in Column I to a number.
I am using the following macro to do so, however I am getting zeros in rows
that do not have any contents in their cells. Can you tell me how to change
the code below so that only the cells with contents in Column I will be
converted to numbers?

Sub Macro5()
Columns("J:J").Select
Selection.Insert Shift:=xlToRight
Range("J2").Select
ActiveCell.FormulaR1C1 = "1"
Selection.Copy
Range("I2:I100").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

Columns("J:J").Delete

End Sub

 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      4th Dec 2009
Sub Macro5()
Columns("J:J").Select
Selection.Insert Shift:=xlToRight
Range("J2").Select
ActiveCell.FormulaR1C1 = "1"

For Each r In Range("I2:I100")
If Not IsEmpty(r) Then
Range("J2").Copy
r.Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
Next
Columns("J:J").Delete

End Sub
--
Gary''s Student - gsnu200909


"Jazz" wrote:

> I would like to convert all the cells with contents in Column I to a number.
> I am using the following macro to do so, however I am getting zeros in rows
> that do not have any contents in their cells. Can you tell me how to change
> the code below so that only the cells with contents in Column I will be
> converted to numbers?
>
> Sub Macro5()
> Columns("J:J").Select
> Selection.Insert Shift:=xlToRight
> Range("J2").Select
> ActiveCell.FormulaR1C1 = "1"
> Selection.Copy
> Range("I2:I100").Select
> Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
> SkipBlanks:=False, Transpose:=False
> Application.CutCopyMode = False
>
> Columns("J:J").Delete
>
> End Sub
>

 
Reply With Quote
 
JBeaucaire
Guest
Posts: n/a
 
      4th Dec 2009
Use this method to only apply the multiplication to cells with values in them:

=========
Sub Macro5()
Columns("J:J").Insert Shift:=xlToRight
Range("J2") = 1
Range("J2").Copy

Columns("I:I").SpecialCells(xlCellTypeConstants, 23).PasteSpecial _
Paste:=xlPasteAll, Operation:=xlMultiply

Columns("J:J").Delete

End Sub
=========

Does that help?
--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"Jazz" wrote:

> I would like to convert all the cells with contents in Column I to a number.
> I am using the following macro to do so, however I am getting zeros in rows
> that do not have any contents in their cells. Can you tell me how to change
> the code below so that only the cells with contents in Column I will be
> converted to numbers?
>
> Sub Macro5()
> Columns("J:J").Select
> Selection.Insert Shift:=xlToRight
> Range("J2").Select
> ActiveCell.FormulaR1C1 = "1"
> Selection.Copy
> Range("I2:I100").Select
> Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
> SkipBlanks:=False, Transpose:=False
> Application.CutCopyMode = False
>
> Columns("J:J").Delete
>
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert cell contents to range =?Utf-8?B?amdyb2dhbg==?= Microsoft Excel Worksheet Functions 3 17th Jul 2006 09:32 AM
How to convert cell contents =?Utf-8?B?Um9iZXJ0IEp1ZGdl?= Microsoft Excel Worksheet Functions 1 13th Jun 2006 08:04 PM
How to convert cell contents? =?Utf-8?B?Um9iZXJ0IEp1ZGdl?= Microsoft Excel Misc 0 8th Jun 2006 02:46 PM
How do I convert cell contents that are Hex to binary? =?Utf-8?B?S2FyZW5TdWUzMw==?= Microsoft Excel Worksheet Functions 1 21st Feb 2005 05:41 PM
convert cell contents into a comment Paul hunter Microsoft Excel Programming 5 21st Aug 2004 09:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:40 AM.