Copy row and delete rows (1 Viewer)

shades

Registered User.
Local time
Today, 01:20
Joined
Mar 25, 2002
Messages
516
Code:
 For lngCol = 1 To 256
        If IsNull(Sheets(4).cell) Then
         Sheets(4).Col.Delete Shift:=xlLeft
        End If
    Next lngCol

I see that you stayed with your code and not what I supplied.

However, I think your code is doing too much. By that I mean it works okay the first time through, but in each successive running of the code, you will be deleting columns with previous data in other rows (rows above from previous pasting); I suspect you want to delete only that cell. Is that correct?

What error message are you getting?
________
Marijuana pictures
 
Last edited:

le888

Registered User.
Local time
Today, 03:20
Joined
Dec 10, 2003
Messages
344
I have try :

Code:
Private Sub cmdDeletRow_Click()
    Dim lngWS As Long
    Dim lngLastCell As Long, lngCounter
    
'    Sheets("Sheet1").Rows("1:1").Copy Sheets("Sheet4").Range("A1")
    Sheets("Sheet4").Activate
    lngLastCell = Sheets("Sheet4").Range("IV1").End(xlToLeft).Column
    For lngCounter = lngLastCell To 1 Step -1
        MsgBox lngCounter
        MsgBox lngLastCell
        If cells(1, lngCounter).Value = "" Then _
            cells(1, lngCounter).Delete
    Next lngCounter
    For lngWS = 1 To 3
        Sheets("Sheet" & lngWS).Rows("1:1").Delete Shift:=xlUp
    Next lngWS
     
End Sub

An error on line " Sheets("Sheet4").Activate". No message. It pointed to the VBA code.

Try this code:

Code:
    Dim lngWS As Long
    Dim lngLastCell As Long, lngCounter
    Dim lngCol As Long
    
    Sheets(1).Rows("1:1").Copy
    Sheets(4).Paste

Application.DisplayAlerts = False

    For lngWS = 1 To 3
     Sheets(lngWS).Rows("1:1").Delete Shift:=xlUp
    Next lngWS

    For lngCol = 1 To 256
        If IsNull(Sheets(4).cell) Then
         Sheets(4).Col.Delete Shift:=xlLeft
        End If
    Next lngCol
Application.DisplayAlerts = True

Error on line " If IsNull(Sheets(4).cell) Then". No message.

I want to delete empty cells in sheet 4 in the first row. Example:

A B C D E F ...
1 empty 12 empty 10 11 empty
2
3
...

As a result, I would like this:

A B C D E F ...
1 12 10 11
2
3
...


Thanks,

Le
 

Users who are viewing this thread

Top Bottom