Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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
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
Imported Data Not Replacing Existing Data - Excel 2007 Marilyn Excel Discussion (Misc queries) 0 April 27th 09 05:22 PM
adding data to existing data and replacing old one in excel? rex Excel Programming 1 March 4th 07 08:40 PM
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? [email protected] Excel Programming 1 August 31st 06 08:08 PM
Repost:replacing data on a non focused worksheet with calculated data from the same sheet BruceJ[_2_] Excel Programming 0 November 11th 03 02:39 AM
replacing data on a non focused worksheet with calculated data from the same sheet BruceJ[_2_] Excel Programming 0 November 5th 03 05:00 PM


All times are GMT +1. The time now is 06:49 AM.

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"