PDA

View Full Version : VBA Help Moving XL Cell Contents based on data type



cj0467
11-06-2008, 12:44 PM
Hi, I am new to VBA and am having difficulty figuring out how to do the following:

I need to be able to use VBA to search through the C column and find all cells with values which begin with a letter. For each of these, the values need to be moved to the left to the A column and up 1 cell. (Only values that are not letters should remain in the C column). After this has been done, I need all blank rows to be deleted. Does anyone have a solution or something similar I could try to modify to suit my needs?

Any information you can provide will be helpful. Thank you!

mdmackillop
11-06-2008, 12:55 PM
Welcome to VBAX.

Does this work?

Sub MoveTextAndDelete()
Dim cel as range
For Each cel In Columns("C:C").SpecialCells(xlCellTypeConstants, 2)
cel.Cut cel.Offset(-1, -2)
Next
Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

cj0467
11-06-2008, 01:02 PM
It gave me a runtime error '1004'
Application-defined or object-defined error

mdmackillop
11-06-2008, 01:03 PM
Can you post some sample data? Use Manage Attachments in the Go Advanced reply section.

cj0467
11-06-2008, 01:19 PM
Attached is an example of similar data...

mdmackillop
11-06-2008, 01:25 PM
Sub MoveTextAndDelete()
For Each cel In Range("C2:C" & Rows.Count).SpecialCells(xlCellTypeConstants, 2)
cel.Cut cel.Offset(-1, -2)
Next
Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

cj0467
11-06-2008, 01:35 PM
That worked! I see how you modified the range to make it work! Thank you so much!