/ / Odstrániť prázdne alebo nulové stĺpce v rozsahu - Excel, VBA, Excel

Odstrániť prázdne alebo nulové stĺpce v rozsahu - excel, vba, excel-vba

To je to, čo potrebujem: Rozsah hovorí stĺpce F: F, G: G, K: K. Ak sú bunky nulové alebo prázdne iba pre tieto konkrétne stĺpce, odstráňte celý stĺpec. Žiadne opatrenie, ak v ňom existuje iná hodnota.

Nižšie uvádzam to, čo teraz používam. Odstráni sa to však z iných stĺpcov, ktoré by sa nemali vymazať.

LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
LastColumn = Sheets("Sheet1").Cells(9, Columns.Count).End(xlToLeft).Column
lastcol_name_1 = Replace(Cells(1, LastColumn).Address(False, False), "1", "")

"to find letter of last column

With Sheets("Sheet1")
For i = 1 To LastColumn
lastcol_name_1 = Replace(Cells(1, i).Address(False, False), "1", "") "to find letter of last column
If(lastcol_name_1=“K” or lastcol_name_1=”L” or lastcol_name_1=”M”) then ‘write the column name here
If Evaluate("sum(countif(" & .Range(.Cells(10, i), _
.Cells(LastRow, i)).Address & ",{"""",0}))") = LastRow - 10 + 1 Then _
.Columns(i).Delete
Endif
Next i

odpovede:

0 pre odpoveď č. 1

Ak vám rozumiem správne, nasledujúcemali by ste vymazať stĺpce „F“, „G“ a „K“, ak sú prázdne, a posunúť zvyšné stĺpce doľava - za predpokladu, že to je to, čo chcete urobiť tu. Nechal som na mieste toľko kódu, koľko chcete. ako som mohol:

Sub main():

LastColumn = Sheets("Sheet1").Cells(9, Columns.Count).End(xlToLeft).Column
lastcol_name_1 = Replace(Cells(1, LastColumn).Address(False, False), "1", "")

For i = LastColumn To 1 Step -1
lastcol_name_1 = Replace(Cells(1, i).Address(False, False), "1", "")
If (lastcol_name_1 = "F" Or lastcol_name_1 = "G" Or lastcol_name_1 = "K") Then
If Application.CountA(Columns(i).EntireColumn) = 0 Then
Columns(i).Delete Shift:=xlToLeft
End If
End If
Next i

End Sub