ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA Selection.Delete Shift:=xlToLeft (https://www.excelbanter.com/excel-programming/353287-excel-vba-selection-delete-shift-%3Dxltoleft.html)

[email protected]

Excel VBA Selection.Delete Shift:=xlToLeft
 
I have a table and in the column D there are values that could either
be "A" or "T".

What I would like is a macro that could go though each value in column
D and if

The value is "A" Then for that row would shift the data in the row
left...

Range("G4:H4").Select ' Not limited to row 4 but to that specific
row

Selection.Delete Shift:=xlToLeft

Else

If The value is "T" Then for that row would shift the data in the row
left...

Range("H4:J4").Select ' Not limited to row 4 but to that specific
row
Selection.Delete Shift:=xlToLeft

Is this doable?

Brenda...Many thanks.


Dave Peterson

Excel VBA Selection.Delete Shift:=xlToLeft
 
Something like:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim myRng As Range
Dim myCell As Range

Set wks = Worksheets("sheet1")

With wks
Set myRng = .Range("d1", .Cells(.Rows.Count, "D").End(xlUp))
For Each myCell In myRng.Cells
Select Case LCase(myCell.Value)
Case Is = "a"
'G:H
.Cells(myCell.Row, "G").Resize(1, 2).Delete shift:=xlToLeft
Case Is = "t"
'H:J
.Cells(myCell.Row, "H").Resize(1, 3).Delete shift:=xlToLeft
Case Else
Beep
End Select
Next myCell
End With

End Sub

wrote:

I have a table and in the column D there are values that could either
be "A" or "T".

What I would like is a macro that could go though each value in column
D and if

The value is "A" Then for that row would shift the data in the row
left...

Range("G4:H4").Select ' Not limited to row 4 but to that specific
row

Selection.Delete Shift:=xlToLeft

Else

If The value is "T" Then for that row would shift the data in the row
left...

Range("H4:J4").Select ' Not limited to row 4 but to that specific
row
Selection.Delete Shift:=xlToLeft

Is this doable?

Brenda...Many thanks.


--

Dave Peterson


All times are GMT +1. The time now is 05:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com