Modify sub to swap text phrases in cells

M

Max

Hi guys,

How could the sub below be modified for
it to work with for example: text phrases in A1 and A2?
(It currently works only with numbers/integers in A1 and A2)

Private Sub CommandButton1_Click()
Dim x As Integer
x = Range("a1").Value
Range("a1").Value = Range("a2").Value
Range("a2").Value = x
End Sub

Thanks
 
N

Norman Jones

Hi Max,

To operate on text values, change:
Dim x As Integer
to

Dim x As String


To operate on numbers or strings:
Dim x As variant

Incidentally, unless you know that the numeric values to be switche are
integers, you would be better advised to dim as Double or Single.
 
B

Bob Phillips

I don't expect to see you in the programming group Max, otherwise I would
have been there <g>

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top