My vba code does not seem to work, even though there are no errors

yossup

I am trying to loop through all cells in a specified range and replace two different parts of the function in the cell.

However, the code seems to run, and when I put a msgbox LastCol, it returns me the last cell in the row, but the function does not change.

Code:

Sub Function1()

 Dim LastCol As Integer
 Dim i As Integer

    Application.ScreenUpdating = False
     Application.DisplayAlerts = False
    With ActiveSheet
        LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column


    For i = 1 To LastCol

     ActiveWorkbook.Sheets("Data").Range("D3" & i).Replace "4. Apr", "5. May", xlPart
     ActiveWorkbook.Sheets("Data").Range("D3" & i).Replace "April", "May", xlPart


    Next i


End With

Application.ScreenUpdating = True
 Application.DisplayAlerts = True
user4039065

If i was 1 then Range("D3" & i) refers to D31. Try,

 with ActiveWorkbook.Sheets("Data")
     .Range(.cells(3, "D"), .cells(3, LastCol)).Replace What:="4. Apr", replacement:="5. May", LookAt:=xlPart, MatchCase:=false
     .Range(.cells(3, "D"), .cells(3, LastCol)).Replace What:="April", replacement:="May", LookAt:=xlPart, MatchCase:=false
 end with

tbh, it's not at all clear what you mean by 'specified range'.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why Does This Index Number Seem to Work Even Though the Index is Closed?

From Dev

Spring Tool Suite application context xml errors even though all beans seem to work as they should

From Dev

Spring Tool Suite application context xml errors even though all beans seem to work as they should

From Dev

Code seems to work even though a semicolon is missing

From Dev

Simple CORS does not work (even though it should)

From Dev

Why does the code work fine when I compile and run it even though I have not mentioned size of array?

From Dev

Why does the browser send an OPTIONS request even though my frontend code is just making a POST request?

From Dev

New to Java, why doesn't this code work? i++ is 'dead code', and the function does not return a variable of desired type; even though it does

From Dev

Code Igniter blank page with no error display even though display errors are on

From Dev

Code Igniter blank page with no error display even though display errors are on

From Dev

My JQuery image slideshow does not seem to work

From Dev

My login page does not seem to work at all

From Dev

how does this code even work?

From Dev

how does this code even work?

From Dev

Why would the replace with regex not work even though the regex does?

From Dev

Why is my image not loading even though the code is correct?

From Dev

My code isn't overwriting the text file, even though it should be?

From Dev

DataGridView is not using my TypeConverters even though PropertyGrid does

From Dev

Why does my table stay blank even though it echos Success?

From Dev

gradle compile does not seem to be able to resolve "-SNAPSHOT" dependencies even though they exist in artifactory

From Dev

Why does the JFrame object seem to stay alive, even though there aren't references to it?

From Dev

gradle compile does not seem to be able to resolve "-SNAPSHOT" dependencies even though they exist in artifactory

From Dev

why does a device on the network seem to always have the same ip upon reboot, even though they're dhcp?

From Dev

Why is my code slow (does it even work)? [Project Euler 12][Python 3.3]

From Dev

I am trying to use CNN for stock price prediction but my code does not seem to work, what do I need to change or add?

From Dev

Does HTML contenteditable attribute require a =true for it to work? Why does it work without it even though it's not a boolean attribute?

From Dev

JQUERY CSS "display" "block" does not work even though "display" "none" does work....

From Dev

instanceof doesn't seem to work - what's wrong with my code?

From Dev

My code for addClass and removeClass doesnt seem to work with Bootstrap Glyphicons

Related Related

  1. 1

    Why Does This Index Number Seem to Work Even Though the Index is Closed?

  2. 2

    Spring Tool Suite application context xml errors even though all beans seem to work as they should

  3. 3

    Spring Tool Suite application context xml errors even though all beans seem to work as they should

  4. 4

    Code seems to work even though a semicolon is missing

  5. 5

    Simple CORS does not work (even though it should)

  6. 6

    Why does the code work fine when I compile and run it even though I have not mentioned size of array?

  7. 7

    Why does the browser send an OPTIONS request even though my frontend code is just making a POST request?

  8. 8

    New to Java, why doesn't this code work? i++ is 'dead code', and the function does not return a variable of desired type; even though it does

  9. 9

    Code Igniter blank page with no error display even though display errors are on

  10. 10

    Code Igniter blank page with no error display even though display errors are on

  11. 11

    My JQuery image slideshow does not seem to work

  12. 12

    My login page does not seem to work at all

  13. 13

    how does this code even work?

  14. 14

    how does this code even work?

  15. 15

    Why would the replace with regex not work even though the regex does?

  16. 16

    Why is my image not loading even though the code is correct?

  17. 17

    My code isn't overwriting the text file, even though it should be?

  18. 18

    DataGridView is not using my TypeConverters even though PropertyGrid does

  19. 19

    Why does my table stay blank even though it echos Success?

  20. 20

    gradle compile does not seem to be able to resolve "-SNAPSHOT" dependencies even though they exist in artifactory

  21. 21

    Why does the JFrame object seem to stay alive, even though there aren't references to it?

  22. 22

    gradle compile does not seem to be able to resolve "-SNAPSHOT" dependencies even though they exist in artifactory

  23. 23

    why does a device on the network seem to always have the same ip upon reboot, even though they're dhcp?

  24. 24

    Why is my code slow (does it even work)? [Project Euler 12][Python 3.3]

  25. 25

    I am trying to use CNN for stock price prediction but my code does not seem to work, what do I need to change or add?

  26. 26

    Does HTML contenteditable attribute require a =true for it to work? Why does it work without it even though it's not a boolean attribute?

  27. 27

    JQUERY CSS "display" "block" does not work even though "display" "none" does work....

  28. 28

    instanceof doesn't seem to work - what's wrong with my code?

  29. 29

    My code for addClass and removeClass doesnt seem to work with Bootstrap Glyphicons

HotTag

Archive