PC Review


Reply
Thread Tools Rate Thread

copy from a specific character and paste

 
 
Sheela
Guest
Posts: n/a
 
      16th Oct 2009
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 With Quote
 
 
 
 
B Lynn B
Guest
Posts: n/a
 
      16th Oct 2009
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 With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      16th Oct 2009
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" <(E-Mail Removed)> wrote in message
news:699B74B2-05BD-4B92-A5E3-(E-Mail Removed)...
>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 With Quote
 
Sheela
Guest
Posts: n/a
 
      16th Oct 2009

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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy / paste only specific rows Benjamin Microsoft Excel Misc 3 11th Apr 2008 03:14 PM
COPY AND PASTE SPECIFIC ROWS =?Utf-8?B?SEVSTkFO?= Microsoft Excel Misc 2 17th Aug 2006 07:32 PM
Copy/Paste to Specific Row with matching Value =?Utf-8?B?RGF2aWQ=?= Microsoft Excel Programming 0 26th Jul 2006 12:43 PM
copy paste cell character limit Fred Microsoft Excel Misc 1 2nd Dec 2004 08:58 PM
cannot copy and paste specific function Mary C. Lydon Microsoft Excel Worksheet Functions 2 5th Oct 2003 01:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:54 PM.