Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

Excel VBA command button for another worksheet

$
0
0

thanks in advance for the potential answerer.

I have a question with excel VBA, macro. I made a command button that runs the code when I click the button. It works perfectly except for one function.

Dim N As Long, i As Long, Kount As Long
Dim wf As WorksheetFunction

Set wf = Application.WorksheetFunction
N = Cells(1, Columns.Count).End(xlToLeft).Column
For i = N To 1 Step -1
    Kount = wf.CountA(Cells(1, i).EntireColumn)
    If Kount = 1 Or Kount = 0 Then
        Cells(1, i).EntireColumn.Delete
    End If
Next i

This is the function that I want to use, and may because of Defining some variables, it does not work for the command button. When I run this code via macros panel, it works perfectly, but when I copy and paste it into code for the command button, it didn't work.

I hope that my English is understandable and waiting for your kind answer.

Many thanks Always learn a lot from stackoverflow.


Viewing all articles
Browse latest Browse all 88054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>