VBA if cell contain text

Sparda142

Board Regular
Joined
Dec 19, 2018
Messages
52
Hello,

I'm trying to create a VBA that states if within Column A if there is a text then paste to the right. If the cell in column A has a numeric value then do nothing.


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]a[/TD]
[TD]b[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]john[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]jake[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]bill[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Whilst my sample data and setup below may not be possible for this OP, I would point out some possible pitfalls of all the suggestions so far.
In the sheet below, column A is formatted as Text & other columns before running the codes were General.
Whilst all of the column A values can be identified as Text (given the column was formatted that way) the codes from posts 6, 7 & 8 all failed to transfer some of the text values. Further, two of the codes correctly identified the last value as a text value but have transformed it into a numerical (date) value in transferring it to the result column.

This modification of Rick's code seems to work for those values at least.

Code:
Sub Copy_Text_Only()
  Dim Lastrow As Long
  
  Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
  Application.ScreenUpdating = False
  Range("A1:A" & Lastrow).Copy Range("B1")
  On Error Resume Next
  Columns("B").SpecialCells(xlConstants, xlNumbers).Clear
  On Error GoTo 0
  Application.ScreenUpdating = True
End Sub


Excel 2016
ABCDE
11E21E2
2$45$$$45$$$45$$
3($5,55,,5.5,,,5,,E55$)($5,55,,5.5,,,5,,E55$)($5,55,,5.5,,,5,,E55$)
4DEC11-Dec1-DecDEC1
5
6Post 6Post 7Post 8Post 11
Copy Text Values
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top