Another quick question regarding moving data

Z

Zarlot531

In the following piece of code, as you can see I select Column E and
clear the contents for any zero data in the column. What I then need
to do is take any NON-zero data, multiply it by -1 (make it negative,
that is) and then move it over one column (so that it no longe exists
in its original column). How do I do this dynamically? you can see
below I am stuck at the "Else" part.

Thanks a lot!

Columns("E").Select
For Each Cell In Selection
If Cell.Value = 0 Then
Cell.ClearContents
Else: Cell.Cut?????????
End If
Next Cell
 
Z

Zarlot531

I need to move it one cell over to the LEFT for each occurence. Sorry
for the ommission.
 
G

Gary Keramidas

this may work for you (untested)

Sub test()
Dim cell As Range
Dim lastrow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
lastrow = Cells(Rows.Count, "E").End(xlUp).Row

For Each cell In ws.Range("E1:E" & lastrow)
If cell.Value > 0 Then
cell.Offset(0, -1).Value = cell.Value
cell.ClearContents
Else
cell.ClearContents
End If
Next
End Sub
 
Z

Zarlot531

Thanks!!

With your help, this is what worked (see bottom of code):

Option Explicit

Sub DelRw()
Dim lstRw
Dim i
Dim x
Dim CalcMode
Dim Cell As Range
Dim lastrow As Long
Dim ws As Worksheet



With Application
CalcMode = .Calculation
..Calculation = xlCalculationManual
..ScreenUpdating = False
End With
Selection.TextToColumns Destination:=Range("A1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(20, 1), Array(34, 1),
Array(42, 1), Array(52, 1), _
Array(54, 1), Array(66, 1), Array(76, 1), Array(86, 1),
Array(108, 1)), _
TrailingMinusNumbers:=True
Columns("C:G").Select
Selection.Delete Shift:=xlToLeft
lstRw = Cells(Rows.Count, 1).End(xlUp).Row
For i = lstRw To 1 Step -1
x = Cells(i, 3).Value
If Left(x, 4) <> "2745" Then
Cells(i, 3).EntireRow.Delete
End If
Next
Columns("E").Select
For Each Cell In Selection
If Cell.Value = 0 Then
Cell.ClearContents
Else: Cell.Offset(0, -1).Value = Cell.Value * -1
Cell.ClearContents
End If
Next Cell
With Application
..ScreenUpdating = True
..Calculation = CalcMode

End With

End Sub
 

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