Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify sub to swap text phrases in cells

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
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Modify sub to swap text phrases in cells

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.

---
Regards,
Norman


"Max" wrote in message
...
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
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 268
Default Modify sub to swap text phrases in cells

use Dim x as Variant

"Max" wrote:

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
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Modify sub to swap text phrases in cells

Max,

Just declare x as variant.

--
HTH

Bob Phillips

"Max" wrote in message
...
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
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----




  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify sub to swap text phrases in cells

Thanks for the detailed tips, Norman !
Works great ..
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----




  #6   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify sub to swap text phrases in cells

Thanks, Kassie !
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #7   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify sub to swap text phrases in cells

Thanks, Bob !
What kept you? Busy elsewhere, huh <bg
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Modify sub to swap text phrases in cells

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

Bob

"Max" wrote in message
...
Thanks, Bob !
What kept you? Busy elsewhere, huh <bg
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching String for phrases/multiple text strings Altair1972m Excel Worksheet Functions 4 May 16th 09 10:44 AM
How can I swap cells Josh W Excel Discussion (Misc queries) 6 March 10th 09 07:13 PM
Use of Text Phrases in Excel Functions Girija Excel Worksheet Functions 0 March 16th 06 06:31 AM
Text Strings Swap Mzansi Excel Worksheet Functions 1 November 29th 05 11:04 AM
Swap Cells William Wolfe Excel Discussion (Misc queries) 4 June 16th 05 05:18 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"