PDA

View Full Version : Solved: COPY CHARACTER FROM A CELL



NNDRIANA
02-25-2012, 09:09 AM
Hi,

I would like to copy first and last character by VBA.
In cell A1 the character is "F102G" ,I want to put F in cell B1 and G in cell C1.

georgiboy
02-25-2012, 09:56 AM
Range("B1").Value = Left(Range("A1").Value,1)

You should be able to work out the rest ;)

NNDRIANA
02-27-2012, 02:30 AM
thanks
It's Ok just for one cell but i need to do this for All cells on column CODE here is my VBA code

Sub remplir()
Dim i As Integer, derlig As Integer
derlig = Range("A65000").End(xlUp).Row
With Sheets("F")
.Cells(1, 1) = "NUMERO"
.Cells(1, 2) = "ID FACADE"
.Cells(1, 3) = "CODE"
.Cells(1, 4) = "NATURE"
.Cells(1, 5) = "TYPE"
Range("D2").Value = Left(Range("C2").Value, 1)
For i = 2 To derlig
Sheets("F").Cells(i, 2) = Sheets("facade").Cells(i, 2)
Sheets("F").Cells(i + 1, 2) = Sheets("facade").Cells(i + 1, 2)
Sheets("F").Cells(i, 3) = Sheets("facade").Cells(i, 3)
Sheets("F").Cells(i + 1, 3) = Sheets("facade").Cells(i + 1, 3)
Next
End With
End Sub

How to do this by loop.

mancubus
02-27-2012, 03:49 AM
hi.

test with bacup file...


With Sheets("F")
.Cells(1, 1) = "NUMERO"
.Cells(1, 2) = "ID FACADE"
.Cells(1, 3) = "CODE"
.Cells(1, 4) = "NATURE"
.Cells(1, 5) = "TYPE"
For i = 2 To derlig
.Cells(i, 2).Value = Sheets("facade").Cells(i, 2)
.Cells(i, 3).Value = Sheets("facade").Cells(i, 3)
.Cells(i, 4).Value = Left(.Cells(i, 3).Value, 1)
.Cells(i, 5).Value = Right(.Cells(i, 3).Value, 1)
Next
End With

NNDRIANA
02-27-2012, 04:59 AM
it does not work,
here is my files.
From cell C2 with "A1000G" as value,i want to take the first character "A" and after to put it in cells D2 ,for the last character "G" in the cell E2.
I would like to have the same process on the next rows .

mancubus
02-27-2012, 05:17 AM
Sub remplir()

Dim i As Integer, derlig As Integer
derlig = Sheets("facade").Range("A65000").End(xlUp).Row

With Sheets("F")
.Cells(1, 1).Value = "NUMERO"
.Cells(1, 2).Value = "ID FACADE"
.Cells(1, 3).Value = "CODE"
.Cells(1, 4).Value = "NATURE"
.Cells(1, 5).Value = "TYPE"
For i = 2 To derlig
.Cells(i, 1).Value = Sheets("facade").Cells(i, 1) 'added for Numero. you may delete this line
.Cells(i, 2).Value = Sheets("facade").Cells(i, 2)
.Cells(i, 3).Value = Sheets("facade").Cells(i, 3)
.Cells(i, 4).Value = Left(.Cells(i, 3).Value, 1)
.Cells(i, 5).Value = Right(.Cells(i, 3).Value, 1)
Next
End With

End Sub

NNDRIANA
02-27-2012, 05:38 AM
Thank you!

Your code works well.

and when you post a VBA code,How do you put this code in the field like your message.

mancubus
02-27-2012, 07:35 AM
you're wellcome.

hit the green VBA button (or manually write) when posting a message...

[ VBA ] [ /VBA ]

vba tags appear (without spaces)
copy your code between tags...

NNDRIANA
02-27-2012, 08:24 AM
sub test()
End sub

NNDRIANA
02-27-2012, 08:25 AM
thank you!

mancubus
02-27-2012, 08:42 AM
sub test()
End sub

:thumb