PDA

View Full Version : Replace and sort macro



maninjapan
04-08-2011, 08:15 AM
I am trying to sort some numerical data using the following ( I had some one help me with this). When I first started I only had use for single digits 1-9 so it worked fine. Now I need to sort double digits. The problem I have is that when it replaces the "0" with "" it also changes 10's to 1's.

I tried replacing it with a single letter, however after running the macro it left me with #NAME instead of an empty cell. Any advice on a simple fix for this ?

Columns("F:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Range("H1").Select
ActiveCell.FormulaR1C1 = "'B"
Range("I1").Select
ActiveCell.FormulaR1C1 = "'S"

Range("H2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[2]=""B"",RC[3],0)"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]=""S"",RC[2],0)"

Range("H2:I2").Select
Selection.Copy

Range("H3:I" & MyRow).Select
ActiveSheet.Paste

Columns("H:I").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Selection.Replace What:="0", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

maninjapan
04-08-2011, 08:17 AM
This is how I tried to fix it only to end up with cells #NAME in place of the blank cells I need....


Columns("F:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Range("H1").Select
ActiveCell.FormulaR1C1 = "'B"
Range("I1").Select
ActiveCell.FormulaR1C1 = "'S"

Range("H2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[2]=""B"",RC[3],a)"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]=""S"",RC[2],a)"

Range("H2:I2").Select
Selection.Copy

Range("H3:I" & MyRow).Select
ActiveSheet.Paste

Columns("H:I").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Selection.Replace What:="a", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False