Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm new to VBA and running into problem on what is probably a very simple
task. Any help would be greatly appreciated. I have information in a cell like this: 4.5/FNCL 5. I need to copy the information before the / to another cell, and the information after the / to a different cell. This is what I have been doing: dim coupon dim collat coupon = Mid(Sheets("temp").Cells(row, 5).Value, 1, Find("/", Sheets("temp").Cells(row, 5).Value, 1) - 1) collat = Mid(Sheets("temp").Cells(row, 5).Value, Find("/", Sheets("temp").Cells(row, 5).Value, 1) + 1, Len(Sheets("temp").Cells(row, 5).Value)) the formula using mid and find works when i put in a cell in excel, but it's not working in the VBA. when i click debug, it highlights the word "find" saying it doesn't recognize the function. Does anyone know a different way of doing it or what could be wrong? Thank you. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Use the SPLIT() function to split a string. Here is an example with your
value in A1: Sub roc616() v = Range("A1").Value s = Split(v, "/") Range("A2").Value = s(0) Range("A3").Value = s(1) End Sub This will put the two halves in A2 & A3 -- Gary''s Student - gsnu200793 "roc616" wrote: I'm new to VBA and running into problem on what is probably a very simple task. Any help would be greatly appreciated. I have information in a cell like this: 4.5/FNCL 5. I need to copy the information before the / to another cell, and the information after the / to a different cell. This is what I have been doing: dim coupon dim collat coupon = Mid(Sheets("temp").Cells(row, 5).Value, 1, Find("/", Sheets("temp").Cells(row, 5).Value, 1) - 1) collat = Mid(Sheets("temp").Cells(row, 5).Value, Find("/", Sheets("temp").Cells(row, 5).Value, 1) + 1, Len(Sheets("temp").Cells(row, 5).Value)) the formula using mid and find works when i put in a cell in excel, but it's not working in the VBA. when i click debug, it highlights the word "find" saying it doesn't recognize the function. Does anyone know a different way of doing it or what could be wrong? Thank you. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you have a bunch of these entries in a single column, you could insert a
column to the right and then use: select the range Data|text to columns delimited (by /) And you'll get the info in different cells really quickly. You could record a macro when you do it manually if you need the code. roc616 wrote: I'm new to VBA and running into problem on what is probably a very simple task. Any help would be greatly appreciated. I have information in a cell like this: 4.5/FNCL 5. I need to copy the information before the / to another cell, and the information after the / to a different cell. This is what I have been doing: dim coupon dim collat coupon = Mid(Sheets("temp").Cells(row, 5).Value, 1, Find("/", Sheets("temp").Cells(row, 5).Value, 1) - 1) collat = Mid(Sheets("temp").Cells(row, 5).Value, Find("/", Sheets("temp").Cells(row, 5).Value, 1) + 1, Len(Sheets("temp").Cells(row, 5).Value)) the formula using mid and find works when i put in a cell in excel, but it's not working in the VBA. when i click debug, it highlights the word "find" saying it doesn't recognize the function. Does anyone know a different way of doing it or what could be wrong? Thank you. -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this.
Dim coupon Dim collat, pos As Integer cellval = Sheets("temp").Cells(Row, 5).Value pos = InStr(cellval, "/") If pos 0 Then collat = Mid(cellval, pos + 1) coupon = Mid(cellval, 1, pos - 1) MsgBox coupon & ", " & collat End If |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() just in addition to gary's student's code, it code also be done like this: v = Range("A1").Value Range("A2").Value = Split(v, "/")(0) Range("A3").Value = Split(v, "/")(1) -- Gary "roc616" wrote in message ... I'm new to VBA and running into problem on what is probably a very simple task. Any help would be greatly appreciated. I have information in a cell like this: 4.5/FNCL 5. I need to copy the information before the / to another cell, and the information after the / to a different cell. This is what I have been doing: dim coupon dim collat coupon = Mid(Sheets("temp").Cells(row, 5).Value, 1, Find("/", Sheets("temp").Cells(row, 5).Value, 1) - 1) collat = Mid(Sheets("temp").Cells(row, 5).Value, Find("/", Sheets("temp").Cells(row, 5).Value, 1) + 1, Len(Sheets("temp").Cells(row, 5).Value)) the formula using mid and find works when i put in a cell in excel, but it's not working in the VBA. when i click debug, it highlights the word "find" saying it doesn't recognize the function. Does anyone know a different way of doing it or what could be wrong? Thank you. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
String splitting for inconsistent strings | Excel Worksheet Functions | |||
Splitting a text string into string and number | Excel Discussion (Misc queries) | |||
splitting string in 2 parts | Excel Programming | |||
Splitting a String | Excel Programming | |||
Splitting Character String | Excel Worksheet Functions |