Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Replacing Data
In cell A1 I have the word Number 1234. I want to put just the 1234 in
column B for every row that is not blank. Can someone show me how to do that using VBA?? Thanks Bill |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Replacing Data
here's one way, just change the range:
Sub test() Dim cell As Range For Each cell In Range("A1:A100") If cell.Value "" Then cell.Offset(0, 1).Value = Right(cell.Value, _ Len(cell.Value) - InStr(cell.Value, " ")) End If Next End Sub -- Gary "open a adobe file from a command button" osoft.com wrote in message ... In cell "A1" I have the word "Number 1234". I want to put just the "1234" in column B for every row that is not blank. Can someone show me how to do that using VBA?? Thanks Bill |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Replacing Data
Sub rght()
Range("A1") = "Number 1234" myVar = Right(Range("A1"), 4) MsgBox myVar End Sub "open a adobe file from a command button" wrote: In cell A1 I have the word Number 1234. I want to put just the 1234 in column B for every row that is not blank. Can someone show me how to do that using VBA?? Thanks Bill |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Replacing Data
Might as well use the whole thing:
Sub cpyA1rght4() Dim aRng, lastRow lastRow = Cells(Rows.Count,1).End(xlUp).Row Set myRange = Range("A2:A" & lastRow) For each c in myRange If Not c Is Nothing Then aRng = c.Address Range(aRng).Offset(0, 1) = Right(Range("$A$1").Value, 4) End If Next End Sub I didn't run it but it should be OK. If not, just post back. "open a adobe file from a command button" wrote: In cell A1 I have the word Number 1234. I want to put just the 1234 in column B for every row that is not blank. Can someone show me how to do that using VBA?? Thanks Bill |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Replacing Data
this is a general purpose function that extract number from sttrings
cal with =GetNum(A1) where A1 is a cell containing a string with numeric dits and characters. Function GetNum(Cell As Range) MyString = Cell.Value StringLen = Len(MyString) GetNum = 0 For i = 1 To StringLen If (Mid(MyString, i, 1) = 0) And (Mid(MyString, i, 1) <= 9) Then GetNum = (10 * GetNum) + CInt(Mid(MyString, i, 1)) End If Next i End Function "open a adobe file from a command button" wrote: In cell A1 I have the word Number 1234. I want to put just the 1234 in column B for every row that is not blank. Can someone show me how to do that using VBA?? Thanks Bill |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Replacing Data
That work very nicely
Thanks "Joel" wrote: this is a general purpose function that extract number from sttrings cal with =GetNum(A1) where A1 is a cell containing a string with numeric dits and characters. Function GetNum(Cell As Range) MyString = Cell.Value StringLen = Len(MyString) GetNum = 0 For i = 1 To StringLen If (Mid(MyString, i, 1) = 0) And (Mid(MyString, i, 1) <= 9) Then GetNum = (10 * GetNum) + CInt(Mid(MyString, i, 1)) End If Next i End Function "open a adobe file from a command button" wrote: In cell A1 I have the word Number 1234. I want to put just the 1234 in column B for every row that is not blank. Can someone show me how to do that using VBA?? Thanks Bill |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Imported Data Not Replacing Existing Data - Excel 2007 | Excel Discussion (Misc queries) | |||
adding data to existing data and replacing old one in excel? | Excel Programming | |||
Replacing data in a row of sheet1 with data in a row of sheet 2 based on a field in both sheets being the same? | Excel Programming | |||
Repost:replacing data on a non focused worksheet with calculated data from the same sheet | Excel Programming | |||
replacing data on a non focused worksheet with calculated data from the same sheet | Excel Programming |