Help with VBA modification

Yamasaki450

Board Regular
Joined
Oct 22, 2021
Messages
71
Office Version
  1. 2021
Platform
  1. Windows
Hello.

I need some help to modify this VBA... Right now this VBA only works in "Sheet1". I would like it to work in all 8 sheets in my workbook at once... So in "Sheet1, Sheet2, Sheet3, Sheet4, Sheet5, Sheet6, Sheet7, Sheet8"

Is this possible?

Here is VBA i use
VBA Code:
Option Explicit
Sub Delete_White_Cells_And_Shift_Up()
    Dim t As Double: t = Timer
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<-- *** Change sheet name to suit ***
    Dim r As Range
    Set r = ws.Range("L1627:VQX1627").CurrentRegion
    
    Dim a, b
    a = r
    ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
    Dim i As Long, j As Long, k As Long, LRow As Long, LCol As Long
    LRow = r.Rows.Count
    LCol = r.Columns.Count
    k = 1
    For j = 1 To LCol
        For i = 1 To LRow
            If r.Cells(i, j).DisplayFormat.Interior.Color <> RGB(255, 255, 255) Then
                b(k, j) = a(i, j)
                k = k + 1
            End If
        Next i
        k = 1
    Next j
    ws.Range("L1627:VQX1627").Resize(LRow, LCol).Value = b
    MsgBox Timer - t
End Sub
 
This also works i just didnt know where to put this line exactly.

Just so you know for future reference, in VBA any line that starts with an apostrophe is regarded as a comment and is not executed. If you look at his posting again, you can see his comment to you on where your code should have been placed. If he had the arrow pointing the opposite way, it would have made more sense I think but that's just a minor little nitpick.

vba comment.png
 
Last edited:
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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