Excel VBA code not running using F5 only F8

0 votes

The VBA code below runs when the key F8 is pressed, but not when the key F5. It simply doesn't run; it makes no errors of any kind.

Dim LastColumn As Long
Set ws = ActiveSheet
Dim LastRow As Long
LastRow = 0
LastColumn = 0

LastRow = ws.Range("c" & Rows.Count).End(xlUp).Row
LastColumn = ws.Cells(11, ws.Columns.Count).End(xlToLeft).Column
Range(Cells(12, 1), Cells(LastRow, LastColumn)).Select
Selection.SpecialCells(xlCellTypeVisible).Interior.ColorIndex = -4142
delay 60
Range("A1").Select

I tried to delay the code for 60 seconds, maybe it runs too fast but doesn't work either. any help?

Mar 21, 2023 in Others by narikkadan
• 63,600 points
533 views

1 answer to this question.

0 votes

Change your code like this:

Dim LastColumn As Long
Set ws = ActiveSheet ' you should change this to Worksheets("YourSheetName") to be safer
Dim LastRow As Long
LastRow = 0
LastColumn = 0
With ws
    LastRow = .Range("c" & .Rows.Count).End(xlUp).Row
    LastColumn = .Cells(11, .Columns.Count).End(xlToLeft).Column
    .Range(.Cells(12, 1), .Cells(LastRow, LastColumn)).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = -4142
    delay 60
    .Range("A1").Select
End With
answered Mar 21, 2023 by Kithuzzz
• 38,000 points

Related Questions In Others

0 votes
1 answer

Is there a way to test a formula result in excel and type it only once, all within one cell and not using a user defined function?

Use the Let function: =LET(Value,A1+B2+C4+G3+B4,IF(Value>10,"No",Value)) I hope this helps ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
665 views
0 votes
0 answers

Google Maps API throws "Uncaught ReferenceError: google is not defined" only when using AJAX

My page uses the  Google Maps API ...READ MORE

May 17, 2022 in Others by Kichu
• 19,040 points
3,959 views
0 votes
1 answer

Unable to import data in excel from another website using VB code

Replace : Set ieTable = ieDoc.all.Item("report-table") With: Set ieTable = ...READ MORE

answered Sep 21, 2022 in Others by narikkadan
• 63,600 points
780 views
0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
889 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,211 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,662 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
906 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,053 views
0 votes
1 answer

Copy data with filter applied using Excel VBA

Try this: Private Sub CommandButton1_Click() Dim ...READ MORE

answered Mar 19, 2023 in Others by Kithuzzz
• 38,000 points
523 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP