Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy from a specific character and paste
I am having trouble to do the following in a VBA macro.
Find cell value in last row and fist column Copy the string starting from €œ:€ (eg if the cell value is €œabcd: ID€ copy only ID), in that cell And paste that to the last column and second row in the same sheet I know I can use the instr , right and len functions to do get the string value I am looking for, but I am not able to figure out how to copy that and paste into in terms of code. Thank you so much in advance for your help |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy from a specific character and paste
Instead of copy/paste, store the value in a variable, then put it where you
want it. e.g... Sub forSheela() Dim myRng As Range, LastRow As Long, LastColumn As Long Dim myTxt As String Set myRng = ActiveSheet.UsedRange LastRow = myRng.Row + myRng.Rows.Count - 1 LastColumn = myRng.Column + myRng.Columns.Count - 1 myTxt = Cells(LastRow, 1) myTxt = Right(myTxt, Len(myTxt) - InStr(1, myTxt, ": ") - 1) Cells(2, LastColumn - 1) = myTxt End Sub "Sheela" wrote: I am having trouble to do the following in a VBA macro. Find cell value in last row and fist column Copy the string starting from €œ:€ (eg if the cell value is €œabcd: ID€ copy only ID), in that cell And paste that to the last column and second row in the same sheet I know I can use the instr , right and len functions to do get the string value I am looking for, but I am not able to figure out how to copy that and paste into in terms of code. Thank you so much in advance for your help |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy from a specific character and paste
The following macro does what you want. Note that in your example, "abcd:
ID" has a space after the colon. This macro picks up that space. If you don't want that space, change the line: TheValue = Right(TheValue, Len(TheValue) - InStr(TheValue, ":")) to TheValue = Right(TheValue, Len(TheValue) - InStr(TheValue, ":")+1) You can do this with a formula, but you asked for a macro. Otto Sub CopyIt() Dim TheValue As String Dim Dest As Range TheValue = Range("A" & Rows.Count).End(xlUp).Value If InStr(TheValue, ":") 0 Then TheValue = Right(TheValue, Len(TheValue) - InStr(TheValue, ":")) Set Dest = Cells(1, Columns.Count).End(xlToLeft).Offset(1) Dest = TheValue End If End Sub "Sheela" wrote in message ... I am having trouble to do the following in a VBA macro. Find cell value in last row and fist column Copy the string starting from ":" (eg if the cell value is "abcd: ID" copy only ID), in that cell And paste that to the last column and second row in the same sheet I know I can use the instr , right and len functions to do get the string value I am looking for, but I am not able to figure out how to copy that and paste into in terms of code. Thank you so much in advance for your help |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy from a specific character and paste
That's perfect. Thank you very much "B Lynn B" wrote: Instead of copy/paste, store the value in a variable, then put it where you want it. e.g... Sub forSheela() Dim myRng As Range, LastRow As Long, LastColumn As Long Dim myTxt As String Set myRng = ActiveSheet.UsedRange LastRow = myRng.Row + myRng.Rows.Count - 1 LastColumn = myRng.Column + myRng.Columns.Count - 1 myTxt = Cells(LastRow, 1) myTxt = Right(myTxt, Len(myTxt) - InStr(1, myTxt, ": ") - 1) Cells(2, LastColumn - 1) = myTxt End Sub "Sheela" wrote: I am having trouble to do the following in a VBA macro. Find cell value in last row and fist column Copy the string starting from €œ:€ (eg if the cell value is €œabcd: ID€ copy only ID), in that cell And paste that to the last column and second row in the same sheet I know I can use the instr , right and len functions to do get the string value I am looking for, but I am not able to figure out how to copy that and paste into in terms of code. Thank you so much in advance for your help |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Copy, Paste in a specific format | Excel Discussion (Misc queries) | |||
COPY AND PASTE SPECIFIC ROWS | Excel Discussion (Misc queries) | |||
Copy/Paste to Specific Row with matching Value | Excel Programming | |||
Copy and Paste specific data | Excel Programming | |||
copy paste cell character limit | Excel Discussion (Misc queries) |